Knitr: opts_chunk$set() not working in Rscript command

前端 未结 1 735
小蘑菇
小蘑菇 2020-12-06 11:37

I\'m using knitr to create a markdown file from Rmd and I have the following option set at the top of my .Rmd script to hide all results and plots:

```{r, ec         


        
相关标签:
1条回答
  • 2020-12-06 12:30

    I think you need to add

    library("knitr")
    

    to the chunk (you might want to set message=FALSE in the chunk options for that chunk).

    The problem is that when you do

    Rscript -e 'knitr::knit("myfile.Rmd")'
    

    you're not actually attaching the knitr package, which means it isn't in the search path for functions, which means that R can't find the opts_chunk object.

    • Using knitr::opts_chunk might work too ...
    • as you suggested, so does Rscript -e 'library("knitr"); knit("myfile.Rmd")'

    When you click the button in RStudio, RStudio automatically loads knitr in the environment in which it runs knit().

    0 讨论(0)
提交回复
热议问题