ThomasH
ThomasH

Reputation: 840

knitr set_parent() always outputs NULL despite echo=FALSE

I have a master document

\documentclass{article}

\begin{document}

<<main>>=
  a <- 20
  b <- 30
@

<<child-demo, child='child.Rnw', eval=TRUE>>=
@

\end{document}

and a corresponding child document

<<set-parent, echo=FALSE, cache=FALSE>>=
set_parent('mwe.Rnw')
@

<<child-code>>=
  a + b
@

When processing the file, I get the following output

a <- 20
b <- 30

## NULL

a + b
## [1] 50

Using \Sexpr{set_parent('mwe.Rnw')} does not produce the ugly ##NULL in the output, but I would prefer declaring the parent via a chunk, as I try to only use \Sexpr{} outside of chunks

Upvotes: 2

Views: 276

Answers (2)

krlmlr
krlmlr

Reputation: 25454

Consider wrapping the call with invisible:

> invisible(1)
> invisible(1) == 1
[1] TRUE

Hence, invisible(set_parent('mwe.Rnw')) should work without printing NULL. I think this is responsibility of set_parent.

Upvotes: 3

Yihui Xie
Yihui Xie

Reputation: 30114

Although I have fixed the problem in knitr 1.0.6, the answer by user946850 is essential, so I recommend that one to be accepted as the answer. For now, you can install the development version.

Upvotes: 2

Related Questions