[英]Programmatically extract an object from collection of RData files
We work in a production environment, with large datasets assembled from API calls saved as RData files to retain the full environment and subsequent data summaries.我们在生产环境中工作,从 API 调用组装的大型数据集保存为 RData 文件,以保留完整的环境和后续数据摘要。 The RData files are very large, and contain multiple dataframe objects generated with a standard analysis workflow with similar names and structures. RData 文件非常大,包含多个 dataframe 对象,这些对象是使用具有相似名称和结构的标准分析工作流生成的。
I'm looking for a clean way to walk through the collection of RData files, pull a named object from each, then assemble into an AllCohorts dataframe for analysis.我正在寻找一种干净的方式来遍历 RData 文件的集合,从每个文件中提取一个名为 object,然后组装成一个 AllCohorts dataframe 进行分析。
We found a useful solution.我们找到了一个有用的解决方案。
extractorRData <- function(file, object) {
#' Function for extracting an object from a .RData file created by R's save() command
#' Inputs: RData file, object name
E <- new.env()
load(file=file, envir=E)
return(get(object, envir=E, inherits=F))
}
allParams.prior <- extractorRData("priorRun.RData", "allParams")
This approach has proven to be both fast, and flexible.事实证明,这种方法既快速又灵活。 Useful with large data frames that would be slow to reconstruct.对于重建速度较慢的大型数据帧很有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.