simsem / semTools

Useful tools for structural equation modeling
75 stars 36 forks source link

Minor problem with efaUnrotate and compareFit #67

Closed studerus closed 4 years ago

studerus commented 4 years ago

I wanted to run EFAs with increasing number of factors and compare their fit with the following code:

dat <- HolzingerSwineford1939[paste0("x", 1:9)]
unrotated <- lapply(1:3, function(x) efaUnrotate(dat, nf = x))
do.call(compareFit, unrotated)

However, the following error occurred:

Error in do.call(rbind, fitList) : 
  variable names are limited to 10000 bytes

The error doesn't occur if I use:

compareFit(unrotated[[1]], unrotated[[2]], unrotated[[3]])

or

do.call(compareFit, setNames(unrotated, seq_along(unrotated)))
TDJorgensen commented 4 years ago

The error in do.call(compareFit, unrotated) occurs because do.call() expects a list of arguments that are named (see the args= description on the ?do.call help page). You are passing a list without names, so it has no recourse but to try to name the arguments itself by using the information in the list. See what happens when you run lapply(unrotated, enquote); those are what do.call() is trying to name the list elements.

I will close the issue because there is obviously nothing I can add to semTools source code to prevent users calling do.call() without naming the arguments. But as you discovered, using setNames() avoids the error. Another way to avoid the error would be to specifically say that your list is the ... argument of compareFit():

do.call(compareFit, list(... = unrotated))

Perhaps the easiest solution is to avoid unnecessarily using do.call() at all, since the ... in compareFit() already accepts a list (even without names, in which case names will be assigned intuitively):

compareFit(unrotated)