[R] Some unrelated questions.

Keith S Weintraub kw1958 at gmail.com
Mon May 6 18:14:21 CEST 2013


I have been working on an R project that has a few dozen functions.

I have some questions that are only tangentially related and might only be a difference in style.

1. Some of my functions take single-row data.frames as input parameters lists. I don't force the user of the function to provide all of the parameters. I use code within a function to test if a particular parameter (column-name) exists in the data.frame and if so use the value of that parameter in a test. If the parameter doesn't exist in the data.frame then some default behavior applies like so:

       if("rollDown" %in% names(runParams)) rollDown<-runParams[["rollDown"]]
      else rollDown<-0

Is this good style? What are the pitfalls? Is there a better way?

One nice thing about this method is that if I need to add a new parameter I don't have to change the signature of the function.

2. What is a good way to organize a project with dozens of functions in R?

3. My project involves a fair amount of simulation. I am not talking hours but some of my "runs" take up to 30 minutes.

Suppose I have a "control" function that calls a number of other functions that might benefit from compilation (using the compiler package). Is it better to compile the called functions inside or outside the control function?

Is there a good "idiom" or standardized way of turning compilation of the called functions on and off? What about debugging (I use the debug package)?

I am perfectly happy with pointers to articles, books and code.

Thanks much for your time,


More information about the R-help mailing list