Hello, I would like to save the results in a specified file name. Here is a test example: aa <- function(xx, newname) { yy <- xx^2 rdName <- file.path(paste(newname, ".RData", sep = "")) assign(eval(newname), yy) save(newname, file=rdName) ## FIXME } aa(3, "test") load("test.RData") ls() I would like to see test (which should store 9) rather than newname (which stores "test") Please let me know how to do this. Thanks. -Nitin _________________________________________________________________________________ stings, and more! tv.yahoo.com/collections/3658
Nitin Jain wrote:> Hello, > > I would like to save the results in a specified file name. Here is a test example: > > > aa <- function(xx, newname) { > yy <- xx^2 > rdName <- file.path(paste(newname, ".RData", sep = "")) > assign(eval(newname), yy) > save(newname, file=rdName) ## FIXME > } > > > aa(3, "test") > > load("test.RData") > ls() > > I would like to see test (which should store 9) rather than newname (which stores "test") > > Please let me know how to do this. > > Thanks. > -NitinFYI see also the Save and Load functions in the Hmisc package. -Frank> > > > _________________________________________________________________________________ > stings, and more! > tv.yahoo.com/collections/3658 > > ______________________________________________ > R-help at r-project.org mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University
>From the help page for save:Arguments: ...: the names of the objects to be saved (as symbols or character strings). list: A character vector containing the names of objects to be saved. so you need save(list=newname, ...). On Sun, 23 Sep 2007, Nitin Jain wrote:> Hello, > > I would like to save the results in a specified file name. Here is a > test example: > > aa <- function(xx, newname) { > yy <- xx^2 > rdName <- file.path(paste(newname, ".RData", sep = "")) > assign(eval(newname), yy) > save(newname, file=rdName) ## FIXME > } > > > aa(3, "test") > > load("test.RData") > ls() > > I would like to see test (which should store 9) rather than newname > (which stores "test") > > Please let me know how to do this. > > Thanks. > -Nitin-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, stats.ox.ac.uk/~ripley University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Thanks Professor Ripley and Professor Harrell. Yes, save(list=newname, ...) works. Best, Nitin ----- Original Message ---- From: Prof Brian Ripley <ripley at stats.ox.ac.uk> To: Nitin Jain <njain at alumni.virginia.edu> Cc: R-help at stat.math.ethz.ch Sent: Sunday, September 23, 2007 11:14:37 AM Subject: Re: [R] saving results under specified file name>From the help page for save:Arguments: ...: the names of the objects to be saved (as symbols or character strings). list: A character vector containing the names of objects to be saved. so you need save(list=newname, ...). On Sun, 23 Sep 2007, Nitin Jain wrote:> Hello, > > I would like to save the results in a specified file name. Here is a > test example: > > aa <- function(xx, newname) { > yy <- xx^2 > rdName <- file.path(paste(newname, ".RData", sep = "")) > assign(eval(newname), yy) > save(newname, file=rdName) ## FIXME > } > > > aa(3, "test") > > load("test.RData") > ls() > > I would like to see test (which should store 9) rather than newname > (which stores "test") > > Please let me know how to do this. > > Thanks. > -Nitin-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, stats.ox.ac.uk/~ripley University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 ______________________________________________ R-help at r-project.org mailing list stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ____________________________________________________________________________________ Luggage? GPS? Comic books? Check out fitting gifts for grads at Yahoo! Search search.yahoo.com/search?fr=oni_on_mail&p=graduation+gifts&cs=bz