I would like to have a set of functions stored in a separate .R file.
Instead of using read_chunk() to read them all in as a block, I would
like source() the whole file and then display the functions one at a
time, with syntax highlighting.
I can get part of the way there via
<<>>=
source("myfunctions.R")
@
Now describe the first function and show it:
<<echo=FALSE,comment=>>=
first_function
@
But this doesn't get highlighted since it is treated as R *output*
rather than code.
I see that I could do something manual like this:
<<echo=FALSE,results=asis>>=
highlight(textConnection(deparse(first_function)),renderer=renderer_latex(document=FALSE))
@
But there must be a more elegant way to do this via hooks?
(This also drops comments in the source code, which I would like to
retain ...)
on a related note, I can get line numbers in a chunk by (1) installing
highlight 0.3.2 from r-forge and (2) putting show_line_numbers=TRUE into
the hack above; is there a simple/recommended way to enable this in a chunk?
thanks
Ben Bolker
Line numbers will be supported once highlight is on CRAN. I pinged
Romain twice about this. He seemed to have an unsolved problem with R
CMD check.
Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA