To avoid creating R functions with many arguments that define the settings for a single object, I put them in a list,
list_my_obj <- list("var1" = ..., "var2" = ..., ..., "varN" = ...)
class(list_my_obj) <- "my_obj"
Then I define functions that take such a list as an argument, and inject the elements of the list into the scope of the function:
my_fun <- function(list_my_obj) {
stopifnot(class(list_my_obj) == "my_obj")
list2env(list_my_obj, envir=environment())
rm(list_my_obj)
var_sum <- var1 + var2
(...)
}
Putting the list items in the scope of the function allows me not to call them with list_my_obj$var1, list_my_obj$var2, etc., later in the function, which will reduce the readability of the code.
This solution works fine, however, it triggers a note at startup R CMD checksaying "there is no visible binding for the global variable" for var1, var2, ... varN.
To avoid such notes, one could simply create new variables at the beginning of the body of the "manual" function for each element of the list:
var1 <- list_my_obj$var1
(...)
varN <- list_my_obj$varN
, N .
, R CMD ?
!