Search code examples
rr-markdownknitrgnu-parallel

Rendering many Rmds from command line using GNU parallel


To knit an Rmd from the command line, you can do the following and it creates an HTML

Rscript -e "rmarkdown::knit('test.Rmd')"

I want to do this for many Rmds using GNU parallel, I've tried this and various versions of it where I move the quotes around

find -name "*.Rmd" | parallel Rscript -e "rmarkdown::render('{}')"

But I keep getting errors.

/bin/bash: -c: line 0: syntax error near unexpected token `('
/bin/bash: -c: line 0: `Rscript -e rmarkdown::render('./test.Rmd')'

I think this is something to do with where the quotation marks are because I get different errors depending on where I put them. What is the problem? Is it doing something funny like only trying to parallelize Rscript and not what comes after it?


Solution

  • From man parallel:

       If you get errors like:
    
         sh: -c: line 0: syntax error near unexpected token
         sh: Syntax error: Unterminated quoted string
         sh: -c: line 0: unexpected EOF while looking for matching `''
         sh: -c: line 1: syntax error: unexpected end of file
         zsh:1: no matches found:
    
       then you might try using -q.
    

    So:

    find -name "*.Rmd" | parallel -q Rscript -e "rmarkdown::render('{}')"