Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
356 views
in Technique[技术] by (71.8m points)

listing contents of an R data file without loading

I sometimes use print( load( "myDataFile.RData" ) ) to list the contents of a data file when I load it. Is there a way to list the contents without loading the objects contained in the data file?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I do not think you could do that without loading the object.

A solution could be to save the R objects with a wrapper to save, which function would save the object AND the structure of the object to a special Rdata file. Later you could load the special binary file with a wrapper to load, where you could specify to only list the structure of the data.

I have done something like this in a very basic package, named saves, can be found on CRAN.


Update: I made up a very simple metadata solution

save.ls <- function(x, file) {
    save(list=x, file=file)
    l <- ls()
    save(l, file=paste(file, 'ls', sep=''))
}
load.ls <- function(file) {
    attach(paste(file, 'ls', sep=''));
    return(l)
    detach(pos=2)
}

Save with save.ls instead of save and load with load.ls to test. Meta information is saved in separate file (ending in "ls"), but the mechanism could be improved easily e.g. making a tar archive (like I do in the package linked above) of the Rdata object and the file containing the metadata.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...