Reputation: 973
I'm working on a script in RStudio which has become pretty large over the past weeks. New features, of course, depend on objects and functions defined in other parts of the script but it's tedious to find the corresponding lines and execute these individually. I would rather write a little function that loads all desired objects (which are stored as .RData) and functions at once. However, if I naively copy-paste the load()-statements and function definitions in a function and execute it, nothing happens.
Any solution for this?
Upvotes: 1
Views: 47
Reputation: 13856
Hi for loading all the RData from a rep you can do like this :
r_datas <- list.files( path = "DATA/", full.names = TRUE, pattern = ".*\\.RData" )
invisible( lapply( X = r_datas, FUN = load, envir = .GlobalEnv ) )
Upvotes: 0
Reputation: 44525
Look at the envir
argument to load
. Inside a function, load
will load into the function's environment, not the global environment. You can either modify the envir
argument (perhaps to .GlobalEnv
), or return all the elements from the function as a list and then do with them as you wish.
Upvotes: 2