2

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

4

2 に答える 2

3

呼び出しをinvisible:でラップすることを検討してください。

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

したがって、invisible(set_parent('mwe.Rnw'))印刷せずに動作するはずNULLです。これはの責任だと思いますset_parent

于 2013-01-23T19:31:18.090 に答える
2

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.

于 2013-01-23T20:29:51.967 に答える