[R] R Design Question...

Jason Rupert jasonkrupert at yahoo.com
Fri Nov 6 18:57:19 CET 2009


This is primarily a design question so any feedback is very much appreciated.  I have a list of several plotting routines that are optional, so currently I include them in an array when I want to call them, e.g. 
plotting_array<-c("PlotHouses.R", "PlotNeighborhood.R", "LinearRegressionOfHomePrices.R", "HistogramSquareFootage.R")

Should I want to plot fewer, I just remove them from the array, e.g. 
plotting_array<-c("PlotHouses.R", "PlotNeighborhood.R")

I plan to make these into functions, but I have not had an opportunity to do so just yet.  I plan to convert them into functions in the coming weeks/months.   Right now it is just calling the individual files and running the code in each one and returning.   
source(plotting_array)

I have them broken up into separate files to help keep things organized and cut down on the size of the main code. 


I want to get away from changing the length of the array, and to something a bit more robust, so the idea is to move over to more of a switching logic approach, e.g.  

plotting_array<-c(PlotHouses = TRUE, PlotNeighborhood = TRUE, LinearRegressionOfHomePrices = FALSE, HistogramSquareFootage = FALSE)
plotting_files<-c("PlotHouses.R", "PlotNeighborhood.R", "LinearRegressionOfHomePrices.R", "HistogramSquareFootage.R")
plotting_df<-data.frame(plotting_array, plotting_files)
plotting_true_df<-plotting_df[which(plotting_df$plotting_array==TRUE),]

source(plotting_true_$plotting_files)

Is there another method that is more perfered for handling a large number of optional plotting scripts/function that sometimes get called an other times don's?

I really don't want to have a big number of if statements checking to see if their flag is true, and was hoping to use more of a dynamic approach.  

Thanks again for any insights.







More information about the R-help mailing list