Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function commenting conventions in R

Tags:

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

like image 493
Hamy Avatar asked Jun 12 '11 20:06

Hamy


People also ask

How do you comment a function in R?

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.

How do you write comments in R?

Comments starts with a # . When executing code, R will ignore anything that starts with # .

What is naming convention in R?

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.

Are spaces important in R?

R extension. File names should be meaningful. File names should not contain / and spaces. Instead, a dash ( - ) or underscore ( _ ) should be used.


1 Answers

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!

like image 101
Chase Avatar answered Oct 12 '22 01:10

Chase