[R] Assigning a new name to object loaded with "load()"

Michael Young michaeltyoung at gmail.com
Sat Jul 28 01:35:42 CEST 2012


Another method, similar to William's.

x <- 3
save(x,file="test.Rdata")
x <- 4

y <- local({	
	load("test.Rdata")
	stopifnot(length(ls())==1)
	environment()[[ls()]]
})


On Fri, Jul 27, 2012 at 3:53 PM, Rolf Turner <rolf.turner at xtra.co.nz> wrote:
> On 28/07/12 06:59, Alireza Mahani wrote:
>>
>> I would like to load a binary file into R using load(), and then assign a
>> new
>> name to it, regardless of the name it was saved under. Can you please
>> provide a code sample? Thank you!
>
>
> Ummm,  what is the antecedent of the pronoun "it" in the forgoing?
>
> The structure of your sentence makes it sound like "it" refers to
> ***the binary file*** --- but I don't believe that's what you mean.
>
> If you by "it" you mean an object (the object? one of the objects?) in
> the saved binary file, then something like:
>
>     y <- x
>     rm(x)
>
> should do what you want.
>
> Distinguish the container from the thing(s) contained.
>
>     cheers,
>
>         Rolf Turner
>
>
> ______________________________________________
> 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.



More information about the R-help mailing list