[R] Assigning a new name to object loaded with "load()"
William Dunlap
wdunlap at tibco.com
Sat Jul 28 00:48:10 CEST 2012
Here is one way. You seem to assume that the save file contains
exactly one object and this function makes the same assumption:
theObjectSavedIn <- function(saveFile) {
env <- new.env()
load(saveFile, envir=env)
loadedObjects <- objects(env, all=TRUE)
stopifnot(length(loadedObjects)==1)
env[[loadedObjects]]
}
Use it as
> tfile <- tempfile()
> myObj <- 101:107
> save(myObj, file=tfile)
> savedObj <- theObjectSavedIn(tfile)
> savedObj
[1] 101 102 103 104 105 106 107
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of Alireza Mahani
> Sent: Friday, July 27, 2012 11:59 AM
> To: r-help at r-project.org
> Subject: [R] Assigning a new name to object loaded with "load()"
>
> 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!
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Assigning-a-new-name-to-
> object-loaded-with-load-tp4638144.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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