cjvanlissa / tidySEM

55 stars 7 forks source link

issue with new lavaan parser #79

Open yrosseel opened 11 months ago

yrosseel commented 11 months ago

The current lavaan syntax parser strips all spaces. The new parser does not (so that we can better detect syntax mistakes), but this implies that operators like "=~" or "~~" should (ideally) not include a space.

In man/syntax.Rd line 27 , there is an example where this goes wrong (with the new parser). The reason is that the R parser is automatically adding a space (in ~~), it would seem:

dummy <- function(x) { return(x) }
dummy(a~~b)
# a ~ ~b 

A solution is perhaps to manually strip the spaces again (ideally of the operators only) just before calling the lavParseModelString() function (eg just before line 122 in syntax-add_paths.R)?

cjvanlissa commented 11 months ago

@yrosseel which version of lavaan can I install to test the new behavior?

yrosseel commented 11 months ago

I just pushed the latest version of lavaan to github, which includes the new parser. Per default, the old parser is still used, but you can switch to the new parser using the parser = "new" argument. The lavParseModelString() function does use the new parser per default. In any case, spaces in operators (like "= ~" or "~ ~") will be tolerated for now with a warning, so there is no big hurry. But eventually, I would prefer to trigger an error if they occur in the model syntax.

cjvanlissa commented 11 months ago

Thank you Yves! I will get to it.