An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130326/587fe9a5/attachment.pl>
Execution halted when I use knitr and Rscript with opts_chunk
3 messages · Marcus Nunes, Duncan Murdoch, Yihui Xie
On 26/03/2013 12:26 PM, Marcus Nunes wrote:
Hello all,
I wrote a bash script in Mac OS that takes my .rnw file, knit it and then
makes a .pdf. To knit my file, I'm using the command
Rscript -e "library(knitr); knit('file.rnw', encoding='utf8')"
and everything works fine. However, I don't want the ## characters in my
final document. I tested, using R prompt, the following commands
library(knitr)
opts_chunk$set(comment=NA)
knit('file.rnw', encoding='utf8')
and they give me exactly what I want: the document without comments in the
R commands output. But if I try to run
Rscript -e "library(knitr); opts_chunk$set(comment=NA); knit('livro.rnw',
encoding='utf8')"
I get
Error: could not find function "opts_chunk"
Execution halted
as result. What am I doing wrong? How can I ask for options for my chunk in
knitr using the command line?
That looks like a bash problem: it appears to be replacing $set with a blank string. Use appropriate quoting or escaping to tell it not to do that. (I think using single quotes around the command will work; you'll need double quotes within it.) Duncan Murdoch
Yes I believe that was the problem. Same question asked here: https://github.com/yihui/knitr/issues/162#issuecomment-9017997 BTW, for future reference, this question was cross-posted at http://stackoverflow.com/questions/15640353/execution-halted-when-i-use-knitr-and-rscript-with-opts-chunk Regards, Yihui -- Yihui Xie <xieyihui at gmail.com> Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA On Tue, Mar 26, 2013 at 12:30 PM, Duncan Murdoch
<murdoch.duncan at gmail.com> wrote:
On 26/03/2013 12:26 PM, Marcus Nunes wrote:
Hello all,
I wrote a bash script in Mac OS that takes my .rnw file, knit it and then
makes a .pdf. To knit my file, I'm using the command
Rscript -e "library(knitr); knit('file.rnw', encoding='utf8')"
and everything works fine. However, I don't want the ## characters in my
final document. I tested, using R prompt, the following commands
library(knitr)
opts_chunk$set(comment=NA)
knit('file.rnw', encoding='utf8')
and they give me exactly what I want: the document without comments in the
R commands output. But if I try to run
Rscript -e "library(knitr); opts_chunk$set(comment=NA); knit('livro.rnw',
encoding='utf8')"
I get
Error: could not find function "opts_chunk"
Execution halted
as result. What am I doing wrong? How can I ask for options for my chunk
in
knitr using the command line?
That looks like a bash problem: it appears to be replacing $set with a blank string. Use appropriate quoting or escaping to tell it not to do that. (I think using single quotes around the command will work; you'll need double quotes within it.) Duncan Murdoch