4

我在带有 R (3.01) 的 OS X (10.8.3) 上使用 Lyx (2.06)。我正在尝试将 knitr 文件导入 Lyx。Lyx 能够找到 Rstudio,但 Rscript 在setwd命令上失败。Lyx 的错误日志如下。任何帮助将非常感激。(我在 Stackoverflow 上的第一篇文章。为任何尴尬的格式提前道歉。)

10:43:17.114: Importing ~/Documents/Temp/stest.lyx...
10:43:17.122: Rscript --verbose --no-save --no-restore "/Applications/LyX.app/Contents/Resources/scripts /lyxknitr.R" "/Users/wms5f/Documents/Temp/""stest.Rnw" "/Users/wms5f/Documents/Temp/""stest.tex"  "/Users/wms5f/Documents/Temp/"
10:43:17.124: running
10:43:17.125:   '/Library/Frameworks/R.framework/Versions/3.0/Resources/bin/R --slave --no-restore --no-save --no-restore --file=/Applications/LyX.app/Contents/Resources/scripts/lyxknitr.R --args /Users/wms5f/Docu
10:43:17.126: ments/Temp/stest.Rnw /Users/wms5f/Documents/Temp/stest.tex'
10:43:17.126: 
<.snip.>
10:43:18.424: 
10:43:18.603: Package `sm', version 2.2-5: type help(sm) for summary information
10:43:20.609: Error in setwd(.cmdargs[4]) : missing value is invalid
10:43:20.610: Execution halted

Running: Rscript --verbose --no-save --no-restore "/Applications/LyX.app/Contents/Resources/scripts/lyxknitr.R" "/Users/wms5f/Documents/Temp/""stest.Rnw" "/Users/wms5f/Documents/Temp/""stest.tex"  "/Users/wms5f/Documents/Temp/"
support/Systemcall.cpp (273): Systemcall: 'Rscript --verbose --no-save --no-restore "/Applications/LyX.app/Contents/Resources/scripts/lyxknitr.R" "/Users/wms5f/Documents/Temp/""stest.Rnw" "/Users/wms5f/Documents/Temp/""stest.tex"  "/Users/wms5f/Documents/Temp/"' finished with exit code 1
Error: Cannot convert file

An error occurred while running:
Rscript --verbose --no-save --no-restore
"/Applications/LyX.app/Contents/Resources/scripts/lyxknitr.R"
"/Users/wms5f/Documents/Temp/""stest.Rnw"
"/Users/wms5f/Documents/Temp/""stest.tex"  "/Users/wms5f/Documents/Temp/"
10:43:55.912: file not imported!
10:43:55.913: (buffer-import knitr)
10:44:04.097: (dialog-show prefs: ⌘,)

补充说明:

我在最初的帖子中可能不是很清楚。我有一个名为 stest.Rnw 的文件,其中包含以下 sweave 代码:

\documentclass{article}
\begin{document}

Test

\end{document}

如果我尝试使用该选项将此文件导入 Lyx 2.06 Import -> Rnw (knitr),Lyx 会生成以下系统命令:

Rscript --verbose --no-save --no-restore "/Applications/LyX.app/Contents/Resources/scripts/lyxknitr.R" "/Users/wms5f/Documents/Temp/""stest2.Rnw" "/Users/wms5f/Documents/Temp/""stest2.tex"  "/Users/wms5f/Documents/Temp/"

当从 bash 提示符以及从 Lyx 中运行时,此命令会失败。我注意到额外的双引号,但在运行脚本之前删除它们会得到相同的结果。Rscript 似乎无法解析第四个参数,它只是一个目录。R 永远无法解析 sweave,因为它在初始解析 Lyx 传递给它的参数时失败了。至少这是我阅读错误消息的方式。

我希望这是有帮助的。

4

1 回答 1

3

您试图将 Rnw 文件导入LyX,但 LyX 2.0.6 尚不支持。它计划出现在 LyX 2.1:http ://www.lyx.org/trac/ticket/7838

LyX 2.1 发布后,您可以通过命令行导入:

tex2lyx -n -m knitr stest.Rnw

我不确定为什么 LyXRscript在导入文件时需要调用。您可能需要向 LyX 提交错误报告。

于 2013-06-10T00:18:45.770 回答