
Update March 2013:  utils has function `SaveThem()` 
This is probably outdated (is originally from Dec 2012 or earlier)  
I am archiving this. 


saveit2 <- function(..., directory=getwd(), createSubDir=TRUE, pos=1)  {
  ## saves obj to file of type .Rda and with 
  ##     name of file same as name of obj + time stamp
  ##     in location: directory
  ##     createSubDir:  if TRUE, will create subdirectory data_bak 
  ##                inside directory and use that folder. (if alreaddy exists, will just use)
  ##
  ## returns:  the path/to/file.Rda where obj was saved
  ##
  ## TODO:  The Rdata file names the data 'obj'.  I dont think this can be fixed, other than to load the .Rda and then myName <- obj;  rm(obj, pos=#).  
  ##   this function is useful primarily for a quick save with a timestamp in a useful directory. 


  objNames <- as.character(substitute(list(...)))[-1L]

  # get object from the parent environment
#  objName <- as.character(match.call()[[2]])

  # TODO:
  #  modify with ... to allow multiple objects and/or a list of objects

  # use subdirectory data_bak unless indicated not to  (create it if needed)
  if (createSubDir) {
    directory <- as.path(directory, "data_bak")
    dir.create(directory, recursive=TRUE, showWarnings=FALSE)
  }

  # create the filename, cleaning objNames of bad chars
  fileName <- paste0(cleanChars(objNames),"_",ts(),".Rda")
  fileWithPath <- as.list( as.path(directory,fileName) )  # convert to list for use with do.call later
    
  return(fileWithPath)

  # Save the object
  do.call(save, args=c(list(objName), envir=parent.frame(pos+1), file=fileWithPath) )
  
  # return the path/to/file
  return(fileWithPath)
}


#------------------#
# SAMPLE DATA
OBJ1 <- matrix(5:24, ncol=5)
OBJ2 <- list(c("a", "b", "c"), list(1:5, "hello", "world")) 
#------------------#


(toLoadMany <- saveit2(OBJ1, OBJ2, directory="~/git/misc/rscripts/ggplot2 Learning/") )


rm(OBJ1, OBJ2)
OBJ2
load(toLoadMany)
OBJ2
