yrosseel / lavaan

an R package for structural equation modeling and more
http://lavaan.org
416 stars 99 forks source link

Error of `unexpected symbol` when using `efa()` #264

Closed psychelzh closed 1 year ago

psychelzh commented 1 year ago

This occurs when some of the data variables are not syntactical, here is a simple reprex:

library(lavaan)
#> This is lavaan 0.6-14
#> lavaan is FREE software! Please report any bugs.
data <- tibble::tibble(
  `1BACK` = rnorm(100),
  `2BACK` = rnorm(100),
  `3BACK` = rnorm(100)
)
efa(data)
#> Error in str2lang(x): <text>:1:4: unexpected symbol
#> 1: ~ 1BACK
#>        ^

Created on 2023-02-21 with reprex v2.0.2

psychelzh commented 1 year ago

A very straight-forward way to workaround this is to add backticks ("`") to all the data variables.

yrosseel commented 1 year ago

Indeed. This is an 'R' thing: variable names cannot start with a digit (without using backticks).

psychelzh commented 1 year ago

Just to make it clear. Will the backticks be added automatically by lavaan or manually by users? If the latter, I do think some documentation needs to be added to inform users.