当我Error in lines[[i]] : subscript out of bounds
尝试编织一个从外部文件读取模型然后将模型放入lavaan
.
我在文件中创建模型.R
:
model <- readLines(con = textConnection('
depression =~ thoughts + pain + brain + use + suic + talk + sitalone +
headaches + app + heart + cheek + cry + sleep + disob + cold +
liedown + worries + alone + annoyed + holdhead + drinkal +
insult + greet + think + mutter + trust + donoth + sad + bad +
weak + notalk + forget + crycont + livedie
'))
cat(model, file = 'scripts/mod.lav.f1.0', sep = '\n')
运行.R
文件时,它将以下内容放入scripts/mod.lav.f1.0
文件中:
depression =~ thoughts + pain + brain + use + suic + talk + sitalone +
headaches + app + heart + cheek + cry + sleep + disob + cold +
liedown + worries + alone + annoyed + holdhead + drinkal +
insult + greet + think + mutter + trust + donoth + sad + bad +
weak + notalk + forget + crycont + livedie
然后我的.rnw
文件读入scripts/mod.lav.f1.0
指定我的模型的文件。
\documentclass{article}
\begin{document}
<<cfa, include=FALSE, tidy=FALSE>>=
# read in model from file
mod.1f.0 <- readLines("scripts/mod.lav.f1.0")
# fit the model
fit.1f.0 <- cfa(mod.1f.0, data = mydata, ordered=items)
@
\end{document}
块中的有问题的陈述似乎是fit.1f.0 <- cfa(mod.1f.0, data = mydata, ordered=items)
. 编织文档时,出现错误:Error in lines[[i]] : subscript out of bounds
.
我能够R
毫无问题地运行该块。模型存储在 中mod.1f.0
,拟合存储在 中fit.1f.0
。
关于导致此错误的原因有什么想法吗?