-
Notifications
You must be signed in to change notification settings - Fork 2
Description
When providing explanatory variables via the dimVar
option, the user may provide a set of total codes for each variable as either a vector of strings or a named list of strings. For the formula interface, only a vector of strings works, and a named lists causes the program to crash with an uninformative error. Below is a minimal reproducible example.
library(SSBtools)
library(GaussSuppression)
dataset <- SSBtoolsData("d2s")
microdata <- MakeMicro(dataset, "freq")
GaussSuppressionFromData(
data = microdata,
formula = ~ region * main_income,
freqVar = "freq",
total = list(region ="SSS", main_income = "ALL"),
primary = FALSE,
protectZeros = FALSE
)
The error this produces is the following:
Error in firstROW[rep(1, NROW(ur)), , drop = FALSE] :
incorrect number of dimensions
Tested on an environment with:
- R 4.3.3
- SSBtools 1.7.5
- GaussSuppression 1.0.0
What I know so far
I think there are only two possibilities: 1) This is unintended behaviour (bug), or 2) instead, the fact that a named list accidentally works for the dimVar
interface is unintended behaviour.
In case of 1) the failure probably stems from FormulaSums.R in the SSBtools package: https://github.com/statisticsnorway/ssb-ssbtools/blob/31d8d68692f15b6a1bd0be155cafbda561bfc2ff/R/FormulaSums.R
However, it is also viable to go for option 2), i.e. define the parameter total
to always be a vector of strings, e.g. total = c(region ="SSS", main_income = "ALL")
in the example above. In this case, this information could be more clearly indicated in the documentation and the GaussSuppressionFromData
function could even sanitize the input before passing it on to SSBtools::ModelMatrix
. Or a more informative error message could be given to the user.