Skip to content

Instantly share code, notes, and snippets.

@yihui
Last active September 30, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yihui/1805862 to your computer and use it in GitHub Desktop.
Save yihui/1805862 to your computer and use it in GitHub Desktop.
print highlighted source of a function
\documentclass{article}
<<insert-fun, echo=FALSE>>=
insert_fun = function(name) {
read_chunk(lines = capture.output(dump(name, '')), labels = paste(name, 'source', sep = '-'))
}
@
\begin{document}
This is ordinary printing:
<<ordinary-print>>=
fivenum
@
We insert the source of fivenum into knitr and print it in the chunk fivenum-source:
<<insert-fivenum, echo=FALSE>>=
insert_fun('fivenum')
<<fivenum-source, eval=FALSE>>=
@
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment