[R] saving results under specified file name

Duncan Murdoch murdoch at stats.uwo.ca
Mon Sep 24 00:24:59 CEST 2007


Frank E Harrell Jr wrote:
> Nitin Jain wrote:
>   
>> Thanks Professor Ripley and Professor Harrell.
>>
>> Yes, save(list=newname, ...) works.
>>
>> Best,
>> Nitin
>>     
>
> What I didn't see how to do with save( ) is to save an object with a 
> user-specified internal name that is different from the current name of 
> the object.  Save in Hmisc goes to extra trouble to accomplish that.
>   

save() can't, but this should do it (untested):

local({ assign(newname, value)
            save(list=newname)
         })

... which may be what you did in Hmisc.

Duncan Murdoch
> Frank
>
>   
>>  
>>
>>
>> ----- 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
>>>       
>
>
>



More information about the R-help mailing list