When I try to use exams2pdf
(e.g., exams2pdf("boxplots.Rmd")
) from the exams package I get the following error:
sh: line 1: : command not found
I can execute usual terminal commands within R using system()
, for example:
system("ls # list files and folders in WD")
What am I missing? Why can't exams2pdf()
use the shell (bash, I assume) correctly? I am using Linux.
Thank you in advance.
Source of the problem: The exams2pdf()
function tries to open the PDF file it has produced in a PDF viewer. I suspect that R finds a wrong or non-existing path for your PDF viewer.
Workaround: As a quick workaround you can tell exams2pdf()
to write the PDF file to a directory where you can open it yourself. For example, to create the file in your current working directory use
exams2pdf("boxplots.Rmd", dir = ".")
And then you can open plain1.pdf
yourself.
Debugging: When you have created the plain1.pdf
file using the code above you can try to open it from R just like R/exams does. On Linux, it takes the following steps:
out <- "plain1.pdf" ## PDF file in current directory
vwr <- getOption("pdfviewer") ## path to your systems's PDF viewer
cmd <- paste(shQuote(vwr), shQuote(out)) ## PDF viewer command to be executed
system(cmd, wait = FALSE) ## run PDF viewer command
On my system the viewer path vwr
and the resulting quoted command cmd
look as follows:
writeLines(c(vwr, cmd))
## /usr/bin/xpdf
## '/usr/bin/xpdf' 'plain1.pdf'
I suspect that your PDF viewer is somehow misconfigured...