[R] wrapper for save function

From: Erik Iverson <iverson_at_biostat.wisc.edu>
Date: Tue, 26 Feb 2008 11:07:35 -0600


Hello -

I would like to create a wrapper to the 'save' function in the base package, but have a small problem with the name of the object that is getting saved in the file. Below is a simple example illustrating my problem.

## BEGIN SAMPLE R CODE
##################################################
## Here is the wrapper for the save function
##################################################

wrapsave <- function(mydata, ...) {

   save(mydata, ...)
}

##################################################
## Create a test data.frame and save it
##################################################

testdf <- data.frame(a = rnorm(10), b = rnorm(10)) wrapsave(testdf, file = "~/test.Rdata")

##################################################
## remove test data.frame and try to load it
##################################################

rm(testdf)
load(file = "~/test.Rdata")

## END SAMPLE R CODE After the load function is called, an object called 'testdf' does not exist in the global environment, but an object called 'mydata' does. I understand why, but I'd like 'wrapsave' to save the object passed to it with the name of the object it was called with, in this case 'testdf'. Is this possible?

Thank you,
Erik Iverson



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 26 Feb 2008 - 17:11:19 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 26 Feb 2008 - 17:30:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive