Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices to handle personal functions in R

I have written personal functions in R that are not specific to one (or a few) projects.

What are the best practices (in R) to put those kind of functions?

Is the best way to do it to have one file that gets sourced at startup? or is there a better (recommended) way to deal with this situation?

like image 470
Chris Watson Avatar asked Feb 26 '14 20:02

Chris Watson


2 Answers

Create a package named "utilities" , put utility functions in that package, try to aim for one function per file, and store the package in a source control system (e.g., GIT, SVN ). It will save you time in the long run.

P.S. .Rprofile tends to get accidentally deleted.

like image 89
MadSeb Avatar answered Nov 15 '22 05:11

MadSeb


If you have many, it would be good to make it into a package that you load each time you start working.

It is probably not a good idea to have a monolithic script with a bunch of functions. Instead break the file up into several files each of which either has only one function (my preference) or has a group of functions that are logically similar. That makes it easier to find things when you need to make changes.

like image 27
Christopher Louden Avatar answered Nov 15 '22 06:11

Christopher Louden