'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 1:[1]

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('{}')"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ole Tange