Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top