Knrit_child gives an error after updating to version 3.0

A script that has been running smoothly for a month has stopped adding my child latex code to my main document after upgrading to version 3.0. The following snippet is used to include text from a compiled test.rnw file in my main document (so that it can be compiled as a single document). Now it just includes the file names of the compiled rnw files.

<<run-all, include=FALSE>>= out = NULL for (i in 1:10) { out = c(out, knit_child('test.rnw', sprintf('test-template-%d.tex', i))) } @ \Sexpr{paste(out, collapse = '\n')} 

When I try to run the knit_child command interactively, I get this error:

 > knit_child('test.rnw', sprintf('test-template-%d.tex', i)) Error in setwd(opts_knit$get("output.dir")) : character argument expected 

Only Running knit () will compile the Latex code, if I run knin_child (), there is no error, but the "out" object simply contains the file name of the child file instead of the contents.

Any ideas how to fix this?

+4
source share
1 answer

You should not use knit_child() interactively. It was designed to be called inside knit() .

As you already noted, knit_child() in the latest version of knitr returns the contents of the child document if you did not specify the second argument. sprintf('test-template-%d.tex', i) supplying the second argument sprintf('test-template-%d.tex', i) , you mean "please write the output to this file and return the file name."

To fix the problem, you need to remove the second argument:

 <<run-all, include=FALSE>>= out = NULL for (i in 1:10) { out = c(out, knit_child('test.rnw')) } @ \Sexpr{paste(out, collapse = '\n')} 
+7
source

Source: https://habr.com/ru/post/1483507/


All Articles