Reputation: 221
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.
Upvotes: 0
Views: 155
Reputation: 94182
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.
Upvotes: 1