[R] several functions in one *.R file in a R package

Jannis bt_jannis at yahoo.de
Tue Sep 6 16:26:20 CEST 2011

Dear list members,

i have build a package which contains a collection of my frequently used functions. To keep the code organized I have broken down some rather extensive and long functions into individual steps and bundled these steps in sub-functions that are called inside the main function. 

To keep an overview over which sub-function belongs to which main function I saved all the respective sub-functions to the same *.R file as their main-function and gave them names beginning with . to somehow hide the sub-functions. The result would be one *.R file in <package>/R for each 'main-function' containing something like:

mainfunction <- function() {

.subfunction1() <- function() {
 #do some stuff
.subfunction2() <- function() {
 #do some more stuff

According to the way I understood the "Writing R Extensions" Manual I expected this to work. When I load the package, however, I get the error message that the sub-functions could not be found. Manually sourcing all files in the <package>/R directory however yields the expected functionality.

In what way am I mistaken here? Any ideas?


More information about the R-help mailing list