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

前端 未结 2 1386
小蘑菇
小蘑菇 2020-12-22 02:52

Here\'s the situation. My R code is supposed to check whether existing RData files in application\'s cache are up-to-date. I do th

相关标签:
2条回答
  • 2020-12-22 03:34

    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))

    0 讨论(0)
  • 2020-12-22 03:42

    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)
    
    0 讨论(0)
提交回复
热议问题