Is there a way to include the externaL code in the tangled file when I have:
<<xref>>=
@
(here xref is a reference to code in an external file)
or
<<internal-ref>>=
<<xref>>
@
Or do I need to source the external file and somehow work from that?
This is an issue when including knitr vignettes in packages. At the final stage of checking on a vignette, R tries to source the tangled file. Missing code causes problems!
I am using version 1.5 of knitr.
I am also using knitr version 1.5, and the second option you offered works fine for me.
Here, the only R code in the document is stored in a named unevaluated chunk in
"child.Rnw":That file and its chunk are read into the main file,
"main.Rnw", by an initial chunk that uses thechild="filename"option. A second chunk evaluates the code:It knits just fine, and more importantly, doing
purl("main.Rnw")produces a tangled file"main.R"that includes all of the R code."main.R"looks like this:I haven't tried running this as a vignette, but since it's not missing any of the source code, it looks it should at least solve your proximal problem...