Last active
September 30, 2015 14:18
-
-
Save yihui/1805862 to your computer and use it in GitHub Desktop.
print highlighted source of a function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\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