lavaan
lavaan copied to clipboard
Support variable names with spaces or provide an informative error message
Test case:
library(lavaan)
d <- data.frame(a = rnorm(100),
`b b`= rnorm(100),
check.names = F )
colnames(d)
sem("a ~ b b", data = d)
This produces an error
Error in lav_data_full(data = data, group = group, cluster = cluster, :
lavaan ERROR: some (observed) variables specified in the model are not found in the dataset: bb
Instead of this error, lavaan should either just estimate the model with the variable that has a space or print an error like: "Lavaan does not support variable names with spaces. Please adjust your model and data. For example, you can convert all spaces in variable names to _ or ."
Good point. The new parser (used by default in the latest github version) already gives a more useful warning:
a ~ b b
^
Error: lavaan->ldw_parse_get_modifier(): invalid modifier symbol (should be '*' or
'?') at line 1, pos 5
In general, the parser cannot know if the user intended 'b + b', 'b*b' or 'b b'. Unless we look at the data, and check for a variable name 'b b'. When found, lavaan could perhaps produce a more informative message (saying that spaces are NOT allowed). I will investigate if this is feasible.
The syntax parser on github now supports names with spaces. But we still need to check if this does not cause any issues.
All seems fine. Closed issue.