This is admittedly somewhat more complicated than what you asked for, because it involves two files instead of just one. Simply put an identifier starting with # - before each function definition and then create empty chunks referring to each one of the identifiers. You could also have several functions in a single R file and still document them separately.
In a script where you want to use fun() you simply add source("fun.R") to source the function definition.
Youtube how do you use 3 finger screen swi for mac code#
This still means that you have to maintain the code for the function definition only once. If you want to use the function in some other script, you can simply source fun.R (and not the markdown file). The Rmarkdown file then reads the function definition from fun.R and adds documentation. The alternative that I propose puts the function definition in its own R script, say fun.R. I did not find a way to do this (even though it might be possible). And then you wanted to somehow source that file into your R script in order to use the function. You wanted to have the function definition in the markdown file together with the documentation. Note that this approach differs slightly from what you requested. But if you insist on putting function definitions in scripts and document them using RMarkdown files, using read_chunk() from the knitr package might be the way to go. I appreciate this may be a beginners question but any help pointing to tutorials and the like would be greatly appreciatedĪs was mentioned in the comments, you should probably create a package for this purpose. I dont really wish to maintain two sets of function files My question is, if i start a new R project, Is it possible to source the r markdown file and use the library of functions i have created just by calling them similarly to if i was sourcing a regular R file. I will put them into an R Markdown file to document them and then be able to read my thinking behind the function if i come back to it months later I'm looking into R Markdown for documenting functions I regularly use.