R function for plotting x number of variables -
i attempting write function inserted larger script. aim of function accept number of input variables , plot them accordingly:
plot_funct <- function(figfolder,var1,var2,var3,...){ nargin <- length(as.list(match.call())) -1
}
this i'm starting from, here have figfolder path of figures should saved (as .pdf), define 'nargin' specifies number of input arguments, , planning on looping through each of arguments (var1,var2, etc) , plot accordingly. main concern have how set function allow number of inouts?
what easier provide list of these variables:
plot_funct = function(figfolder, variable_list, ...) { for(variable in variable_list) { # make plot here } })
or bit more r like:
plot_variable = function(variable, ...) { # make plot here }) plot_funct = function(figfolder, variable_list, ...) { lapply(variable_list, plot_variable, ...) })
you stick separate variables, , use ...
:
plot_function = function(..., figfolder) { variable_list = list(...) # , use of 2 strategies given above, i'll use lapply lapply(variable_list, plot_variable) })
note more pseudo-code real r code, illustrates general strategy.
Comments
Post a Comment