4

I am using Lyx (2.06) on OS X (10.8.3) with R (3.01). I am trying to import a knitr file into Lyx. Lyx is able to find Rstudio but Rscript fails on the setwd command. The error log from Lyx is below. Any help would be much appreciated. (My first post to Stackoverflow. Apologies in advance for any awkward formatting.)

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: ⌘,)

Added clarification:

I may not have been very clear in my initial post. I have a file called stest.Rnw which contains the following sweave code:

\documentclass{article}
\begin{document}

Test

\end{document}

If I try to import this file into Lyx 2.06 using the Import -> Rnw (knitr) option, Lyx generates the following system command:

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/"

This command fails when run from the bash prompt as well as from within Lyx. I noticed the extra double quotes, but removing them before running the script gets the same result. It does not appear that Rscript is able to parse the 4th argument, which is just a directory. R is never getting to parsing the sweave because it is failing on the initial parsing of the arguments passed to it by Lyx. At least this is how I read the error message.

I hope this is helpful.

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • I would pay attention to these lines:10:43:20.609: Error in setwd(.cmdargs[4]) : missing value is invalid 10:43:20.610: Execution halted. Does your script run in R? Do you account for the new environment in Lyx (there are no objects unless you load/create them). – Maxim.K Jun 09 '13 at 15:54
  • I see two close votes already (not mine), perhaps because no R code is presented for testing. I would like to see a worked example. Perhaps searching SO for: `[r] [lyx]` would move things along? Or see if an earlier solution works: http://stackoverflow.com/questions/16707907/lyx-cannot-find-knitr-module OR http://stackoverflow.com/questions/14949036/lyxknitr-code-externalization-with-read-chunkfoo-r-fails – IRTFM Jun 09 '13 at 17:55
  • I added some clarification, which I hope addresses your comments. – user2468454 Jun 09 '13 at 19:12
  • 4
    I do not think this question is off topic. It reflects a long-standing problem in LyX -- the support for importing literate programming documents. – Yihui Xie Jun 11 '13 at 01:04

1 Answers1

3

You were trying to import an Rnw file into LyX, which is not supported in LyX 2.0.6 yet. It is scheduled to appear in LyX 2.1: http://www.lyx.org/trac/ticket/7838

When LyX 2.1 is released, you can import via the command line:

tex2lyx -n -m knitr stest.Rnw

I'm not sure why LyX needs to call Rscript when importing a file. You may want to file a bug report to LyX.

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419