tbates / umx

Making Structural Equation Modeling (SEM) in R quick & powerful
https://tbates.github.io/
44 stars 17 forks source link

umxSummarizeTwinData add age= and check for presence of age columns #164

Closed tbates closed 3 years ago

tbates commented 3 years ago

Maybe add 'age' as an argument, or give user a warning that age is missing?

The function looks for "age" or "age[separator]1" columns in the dataset

data(twinData)
twinData[ , c("age","age1","age2")] <- list(NULL)

umxSummarizeTwinData(twinData, sep = "", selVars = c("wt", "ht"), MZ = MZs, DZ = DZs)

produces the following:

Error in [.data.frame(data, , paste0("age", sep, 1)) : undefined columns selected

tbates commented 3 years ago

try GitHub version now

mcneale commented 3 years ago

IMO "undefined columns selected" sucks as an error message. R should do better. It knows WHICH variable(s) are not found, but does it tell you which ones (out of possibly thousands of possibilities)? No. Bad programmer, go back to school, do not collect $200.

tbates commented 3 years ago

done

tbates commented 3 years ago

Just as a codicil to this issue, most umx functions use umx_check_names, allowing:

umx_check_names(c("mpg", "meaning of life"), mtcars)

Error in umx_check_names(c("mpg", "meaning of life"), mtcars) : Not all required names were found in the data. Missing were: meaning of life