R/applyFunToVectorOfObjects.R

Defines functions applyFunToVectorOfObjects

Documented in applyFunToVectorOfObjects

#' Apply function to a character vector of object names
#' 
#' @param characterVecOfObj A character vector of object/variable names that are currently in working R memory
#' @param FUN A function to be executed upon the objects/variables (not the character strings!)
#' @return A list where each element corresponds to the outputs from the function, and names after the supplied character vector.
#' @export

applyFunToVectorOfObjects <- function(characterVecOfObj, FUN, ...){
  outLstOfVar <- list()
  for(i in 1:length(characterVecOfObj)){
    print(paste("Working on ",characterVecOfObj[i],sep=""))      
    Obj_i <-  get(characterVecOfObj[i])
    Obj_i_new <- FUN(Obj_i, ...)
    outLstOfVar <- lappend(outLstOfVar,assign(x = characterVecOfObj[i],value = Obj_i_new))
  }
  names(outLstOfVar) <- paste(characterVecOfObj,sep="")
  return(outLstOfVar)
}
msxakk89/dat documentation built on Aug. 3, 2020, 6:39 p.m.