[R] Help understanding environments
Davis, Brian
Brian.Davis at uth.tmc.edu
Mon Jun 17 23:02:46 CEST 2013
I have a collection of .RData files that have result objects that I would like to combine. Specifically, skatCohort objects from the skatMeta package, but I've run into a similar issue with simple data.frames also.
If I run something like
FILES <- list.files(path="/path/to/my/results", pattern=".RData$", full.names=TRUE)
combined <- NULL
for (FILE in FILES) {
load(FILE)
if (!is.null(combined)) {
combined <- c(combined, res)
} else {
combined <- res
}
}
I get all my objects combined. However, if I wrap this into a function I get the following error
c_objects <- function(FILES) {
combined <- NULL
for (FILE in FILES) {
load(FILE)
if (!is.null(combined)) {
combined <- c(combined, res)
} else {
combined <- res
}
}
return(combined)
}
combined_results <- c_objects(FILES)
Error in eval(expr, envir, enclos) : object 'combined' not found
How should I write this function such that it can find "combined". I've tried reading the help on envirnaments, and the exisits function but I haven't been able to figure this out. Are there any other resources to read up on this?
Thanks in advance,
-Brian
More information about the R-help
mailing list