(Apologies if this would be better as a comment. I do not have sufficient reputation to post comments.)
The following rule seems to work well when called with just the base file name. It is also possible to have arara
compile the Rnw source all the way to PDF with a single rule, see below.
!config
identifier: knitr
name: knitr
command: <arara> RScript -e "library(knitr); knit('"@{source}"', output='"@{target}"')"
arguments:
- identifier: source
flag: <arara> "@{parameters.source}"
default: <arara> "@{getBasename(file)}".Rnw
- identifier: target
flag: <arara> "@{parameters.target}"
default: <arara> "@{getBasename(file)}".tex
Unfortunately, I was not able to resolve the error in the original question when calling arara
on my source Rnw file. In this case, arara
complains that the file is not found. This is a problem with the rule above, because I want to call arara
again to compile the .tex file to PDF. The directive
% arara: knitr
still exists as line 1 of the .tex file. Therefore, a subsequent call actually runs arara
on the source Rnw file again, rather than what is intended. (I'm not sure why, since I have the Rnw extension listed last in my configuration file, reproduced below.) Of course one could edit the directive manually, but this is clumsy and inconvenient.
So we are still in need of a solution. Here is a simple workaround. This rule first calls knitr
, then the xelatex
engine.
!config
identifier: knitr
name: knitr
commands:
- <arara> RScript -e "library(knitr); knit('"@{source}"', output='"@{target}"')"
- <arara> xelatex "@{target}"
arguments:
- identifier: source
flag: <arara> "@{parameters.source}"
default: <arara> "@{getBasename(file)}".Rnw
- identifier: target
flag: <arara> "@{parameters.target}"
default: <arara> "@{getBasename(file)}".tex
Here is my configuration file that I am using with this rule.
!config
paths:
- <arara> /path/to/my/knitr/rule
filetypes:
- extension: tex
- extension: dtx
- extension: ltx
- extension: Rnw
pattern: ^(\s)*%\s+