Try the list= argument
save(list= c("Date", paste(.....)), file=....)
If you use ..., you'll get bitten by
...: the names of the objects to be saved (as symbols or character
strings).
and the paste() construct is neither. (Internally, it gets converted by
as.character(substitute(list(...))), leading to the "object...not found" that
you see)
The documentation is maybe a little oblique, but the point is that in
bar <- 1234
foo <- "bar"
save(foo) and save("foo") both save the "foo" object, whereas save(list=foo)
will save "bar".
We don't evaluate expressions in ... because then save(foo) would also save
"bar" (we could in principle have different behaviour from symbols and more
general expressions, but that is a certain road to insanity).
-pd
> On 31 Oct 2019, at 10:17 , Christofer Bogaso <[email protected]>
> wrote:
>
> As I said the name 'AAA31' is itself a variable. So I cant hard-code
> it within the save() function
>
> On Thu, Oct 31, 2019 at 2:45 PM Jim Lemon <[email protected]> wrote:
>>
>> Hi Christofer,
>> This is a guess, but have you tried:
>>
>> save(AAA31,file="Save.RData")
>>
>> Jim
>>
>> On Thu, Oct 31, 2019 at 8:10 PM Christofer Bogaso
>> <[email protected]> wrote:
>>>
>>> Hi,
>>>
>>> I wanted to save a few R objects in RData file for some future use.
>>> The names of such R objects are actually dynamic so I used below code
>>> to save them -
>>>
>>> Date = Sys.Date()
>>> assign(paste('AAA', format(Date, "%d"), sep = ""), 5)
>>> save('Date', paste('AAA', format(Date, "%d"), sep = ""), file =
>>> 'Save.RData')
>>>
>>> With this, I am getting below error -
>>>
>>> Error in save("Date", paste("AAA", format(Date, "%d"), sep = ""), file
>>> = "Save.RData") :
>>> object ‘paste("AAA", format(Date, "%d"), sep = "")’ not found
>>>
>>> But I have the object in the workplace -
>>>
>>>> AAA31
>>> [1] 5
>>>
>>> I will really appreciate if someone can point towards the right direction.
>>>
>>> Thanks,
>>>
>>> ______________________________________________
>>> [email protected] mailing list -- To UNSUBSCRIBE and more, see
>>> 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.
>
> ______________________________________________
> [email protected] mailing list -- To UNSUBSCRIBE and more, see
> 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.
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: [email protected] Priv: [email protected]
______________________________________________
[email protected] mailing list -- To UNSUBSCRIBE and more, see
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.