2

So my problem is the following: I have an R markdown file on my Ubuntu 18.04.3 server that I want to be knitted via command line (this works fine with Rscript -e "rmarkdown::render('path/to/file.Rmd')"), so I tried to run this from PHP with the exec() command (obviously using escape characters). The output from PHP is the following: Execution haltedArray ( [0] => Error: unexpected input in "rmarkdown::render(\" [1] => Execution halted ) when running the following lines of PHP:

exec("Rscript -e \"rmarkdown::render(\'path/to/file.Rmd\')\" 2>&1", $output);
print_r($output); 

What is the unexpected input?

1 Answer 1

2

Don't escape the inner ''s

exec("Rscript -e \"rmarkdown::render('path/to/file.Rmd')\" 2>&1", $output);

.. or change the outermost string characters to use single quotes instead of double:

exec('Rscript -e "rmarkdown::render(\'path/to/file.Rmd\')" 2>&1', $output);

.. dont escape both unless you use both, which is ugly and confusing

exec("Rscript -e \"rmarkdown::render(\\\"path/to/file.Rmd\\\")\" 2>&1", $output);

Sign up to request clarification or add additional context in comments.

3 Comments

Why is this answer correct? Why wasn't the original version with escaped double quotes inside double quotes working?
@RedBassett thanks for edit, i rushed to post, was editing but you did it
np, glad it helped.. ruddy quotes will get ya every time

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.