0

当我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

关于导致此错误的原因有什么想法吗?

4

1 回答 1

0

有人给我发了另一个我能够运行的示例,所以我决定删除我的缓存和 RStudio 创建的所有隐藏项目文件。有效。在这样做之前,我只尝试过重新启动 RStudio。

于 2013-10-20T06:01:30.843 回答