简体   繁体   English

如何在多个rdata文件中查找对象

[英]How to find an object within multiple rdata files

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. 我试图找到一种方法,可以搜索包含许多RData和RDA文件的文件夹,以查找我忘记了该对象存在于哪个RDA文件中的特定对象。
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: 您可以将.RData文件(与RDA文件相同吗?)加载到环境中,然后测试该函数是否存在名称:

 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 . 用法只是hasgot("my.RData","foo")来查看foo是否在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. 完整的解决方案可能涉及将其包装在list.files和循环中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM