I am trying to find a way that I can search a folder containing many RData and RDA files to find a specific object that I have forgotten in which RDA file it exists.
Thank you.
You can load a .RData file (is that the same as an RDA file?) into an environment and then test if a name is present with this function:
hasgot=function(f,name){
e=new.env()
load(f,env=e)
name %in% ls(env=e,all.names=TRUE)
}
The following variation might be faster:
hasgot=function(f,name){
e=new.env()
load(f,env=e)
!is.null(e[[name]])
}
Usage is simply hasgot("my.RData","foo")
to see if foo
is in my.RData
. Its not vectorised over either argument, so only feed it one thing at a time.
A full solution for your problem will probably involve wrapping this in list.files
and a loop.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.