I don't think so -- you want to use saveRDS and readRDS if you want to do that.

However, if you are given someone else's .RData and need to avoid a
name collision, this might work.

loadOneName <- function(objName, file, envir = parent.frame(),
assign.on.exit = TRUE) {
    tempEnv <- new.env()
    load(file, envir = tempEnv)
    stopifnot(objName %in% ls(tempEnv))
    if(assign.on.exit) {
        assign(objName, tempEnv[[objName]], envir = envir)
        return(invisible(tempEnv[[objName]]))
    }
    tempEnv[[objName]]
}

Note that's not been thoroughly tested but it seems decent...

Michael

On Tue, Apr 24, 2012 at 2:30 PM, Shi, Tao <shida...@yahoo.com> wrote:
> Hi list,
>
>
> Is there a way to load one specific object from a .RData file which contains 
> multiple data objects?  Thanks,
>
> ...Tao
>
>
> ______________________________________________
> R-help@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.

______________________________________________
R-help@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.

Reply via email to