Lyx / knitr错误

时间:2013-07-26 21:12:40

标签: r knitr lyx

我一直收到这个错误; Rscript --verbose --no-save --no-restore - 我在这里看到其他人也得到了它,所以我不希望它重复。

我只是一个“普通的乔”想要学习一些R并希望能够用lyx / knitr报告,所以我一般都不太了解乳胶或编码。

话虽如此,我会尽力以最佳方式描述问题。

我能够编译knitr文件夹中提供的一些演示,而一些简单的我已经完成了自我。但由于某种原因出现上述错误并且文档被破坏 - 这意味着,即使我删除了所有代码,我也无法编译它。

错误似乎几乎随机出现,在图片中你可以看到错误。第一次测试很顺利 - 虽然它在我使用hist()命令时出现 - 这次它出现在我试图获取工作目录时,我已经能够没有错误地做了。

我不确定这是不是我的错,或者它是否是Knitr / Lyx的错误 - 希望你可以帮助我确定它是什么。

!!编辑; Lyx-log按要求。

22:47:42.732: Previewing ...
22:47:42.739: (buffer-view: Ctrl+R)
22:47:42.779: Rscript --verbose --no-save --no-restore "C:/Program Files (x86)/LyX 2.0/Resources/scripts/lyxknitr.R" "C:/Users/Toddi/AppData/Local/Temp/lyx_tmpdir.Hp4668/lyx_tmpbuf2/""newfile1.Rnw" "C:/Users/Toddi/AppData/Local/Temp/lyx_tmpdir.Hp4668/lyx_tmpbuf2/""newfile1.tex" ISO-8859-15 "C:/Users/Toddi/Documents/"
Running: Rscript --verbose --no-save --no-restore "C:/Program Files (x86)/LyX 2.0/Resources/scripts/lyxknitr.R" "C:/Users/Toddi/AppData/Local/Temp/lyx_tmpdir.Hp4668/lyx_tmpbuf2/""newfile1.Rnw" "C:/Users/Toddi/AppData/Local/Temp/lyx_tmpdir.Hp4668/lyx_tmpbuf2/""newfile1.tex" ISO-8859-15 "C:/Users/Toddi/Documents/"
22:47:43.408: 
  |                                                                       
  |                                                                 |   0%
  |                                             
22:47:43.409:                           
  |......................                                           |  33%
22:47:43.409:   ordinary text without R code
22:47:43.409: 
22:47:43.409: 
  |                                                                       
  |...........................................                      |  67%
22:47:43.409: label: test
22:47:43.410: running
22:47:43.410:   'C:\PROGRA~1\R\R-30~1.1\bin\i386\Rterm.exe --slave --no-restore --no-save --no-restore --file=C:/Program Files (x86)/LyX 2.0/Resources/scripts/lyxknitr.R --args C:/Users/Toddi/AppData/Local/Temp/ly
22:47:43.410: x_tmpdir.Hp4668/lyx_tmpbuf2/newfile1.Rnw C:/Users/Toddi/AppData/Local/Temp/lyx_tmpdir.Hp4668/lyx_tmpbuf2/newfile1.tex ISO-8859-15'
22:47:43.411: 
22:47:43.411: 
22:47:43.411: 
22:47:43.411: processing file: C:/Users/Toddi/AppData/Local/Temp/lyx_tmpdir.Hp4668/lyx_tmpbuf2/newfile1.Rnw
22:47:43.456: 
22:47:43.457: Advarsel i block_exec(params) :
22:47:43.457:   failed to tidy R code in chunk <test>
22:47:43.459: reason: Error in base::parse(text = text, srcfile = NULL) : 3:1: unexpected '@'
22:47:43.459: 2: hist(q)
22:47:43.459: 3: @
22:47:43.460:   ^
22:47:43.460: 
22:47:43.460: Quitting from lines 11-15 (C:/Users/Toddi/AppData/Local/Temp/lyx_tmpdir.Hp4668/lyx_tmpbuf2/newfile1.Rnw) 
22:47:43.461: Fejl i parse(text = x, srcfile = src) : <text>:3:1: unexpected '@'
22:47:43.461: 2: hist(q)
22:47:43.461: 3: @
22:47:43.461:   ^
22:47:43.461: Calls: knit ... evaluate -> parse_all -> parse_all.character -> parse
22:47:43.461: Execution halted
..\..\..\src\support\Systemcall.cpp (273): Systemcall: 'Rscript --verbose --no-save --no-restore "C:/Program Files (x86)/LyX 2.0/Resources/scripts/lyxknitr.R" "C:/Users/Toddi/AppData/Local/Temp/lyx_tmpdir.Hp4668/lyx_tmpbuf2/""newfile1.Rnw" "C:/Users/Toddi/AppData/Local/Temp/lyx_tmpdir.Hp4668/lyx_tmpbuf2/""newfile1.tex" ISO-8859-15 "C:/Users/Toddi/Documents/"' finished with exit code 1
Error: Cannot convert file
----------------------------------------
An error occurred while running:
Rscript --verbose --no-save --no-restore "C:/Program Files (x86)/LyX
2.0/Resources/scripts/lyxknitr.R"
"C:/Users/Toddi/AppData/Local/Temp/lyx_tmpdir.Hp4668/lyx_tmpbuf2/""newfile1....
22:51:00.499: Automatic save done.
22:51:51.362: Error while previewing format: pdf2

编辑2;

你的意思是这个;

% Preview source code for paragraph 0


<<test>>=
q <- rnorm(100)
hist(q)
@<<test2>>=
getwd()
@

我在@<<test>>=之间添加了一行,现在可以了。但我想我已经看到它失败了,我在代码位之间有文本。我会提防这一点并尝试查看将来的源代码,谢谢你的时间!

1 个答案:

答案 0 :(得分:1)

我的猜测是你可能需要在第一个@之后换一个新行。我记得在某些情况下,LyX不会在ERT (evil red text)之后添加新行,这会导致knitr出现问题。我不能肯定LyX会这样做,因为我很少使用Windows,而且我无法在Ubuntu / LyX 2.0.6下重现这个问题。

要验证,请从View-->View source打开源面板,然后查看LaTeX源中的@后是否有新行。

打开源面板和消息面板始终是一个好主意,以确保您看到LyX背后的所有内容,并了解真正的错误。