I'm fairly new to R, and I have been defining some of my own functions in script files. I'm intending for others to re-use them later, and I can't find any guides on R function commenting conventions. Is there any way for me to make help("my_function_name")
show some help? If not, do I just document the function in the script file, so that someone has to print out (or open the source of) a script to see the comments?
Thanks,
Hamy
There are two ways to add multiple single-line comments in R Studio: First way: Select the multiple lines which you want to comment using the cursor and then use the key combination “control + shift + C” to comment or uncomment the selected lines.
Comments starts with a # . When executing code, R will ignore anything that starts with # .
Object naming conventionUse only lowercase letters and numbers. Use underscores ( _ ) (so called snake case) to separate words within a name. Use names that are concise and meaningful (this is not easy!). Generally, variable names should be nouns and function names should be verbs.
R extension. File names should be meaningful. File names should not contain / and spaces. Instead, a dash ( - ) or underscore ( _ ) should be used.
Updating this question December 2019 as the R-universe has changed since 2011 when originally written
My recommended resource is now http://r-pkgs.had.co.nz/
Original answer (links are mostly out of date)
The canonical way to document your functions and make them accessible to others is to make a package. In order for your package to pass the build checks, you have to supply sufficiently detailed help files for each of your functions / datasets.
Check out http://cran.r-project.org/doc/manuals/R-exts.html#Creating-R-packages
This blog post from Rob J Hyndman was very useful and one of the easiest for me to follow: http://robjhyndman.com/researchtips/building-r-packages-for-windows/
I've started using roxygen to assist in making & compiling packages as of late: http://roxygen.org/
Lots of good resources and people to help when you have questions!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With