Can I access R data objects' attributes without fully loading objects from file?

一世执手 提交于 2019-11-29 17:04:11

You can't "really" do it, but you could modify the code in my cgwtools::lsdata function.

function (fnam = ".Rdata") 
{
    x <- load(fnam, envir = environment())
    return(x)
}

This loads, thus taking time and briefly taking memory, and then the local environment disappears. So, add an argument for the items you want to check attributes for, add a line inside the function which does attributes(your_items) ->y ; return (list(x=x,y=y))

And there is a problem with the way you are using load(). When you use save/load you can "freeze-dry" multiple objects to an .RData file. They "re-infalte" into the current environemnt. As a result, when you call load(), it does not return the object(s), it returns a character vector with the names of all the objects that it restored. Since you didn't supply your save() code, i'm not sure what's actually in your load file, but if it was a variable called data, then just call

load(rdataFile)

not

data <- load(rdataFile)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!