首页 > 解决方案 > 比较两个文件头并确保它们具有相同的头,无论顺序如何

问题描述

我想比较两个配置文件,一个是用户生成的,另一个是模板。

我有代码工作,但觉得有更好的方法来处理这个问题。

#config variable designated previously

current.config.template<-'/location/of/template'
default.config<- read.csv(current.config.template,stringsAsFactors = FALSE)

bool<-colnames(default.config) %in% colnames(config)

for(i in bool){
  if(i==FALSE){
    stop("Please use the most recent met-ingest.csv file located /path/to/file/")
  }
}

它有效,但我觉得必须有一种更好的方法来实现这一点,而不是 for 循环中的 if 循环。

标签: rdataframe

解决方案


你不需要循环。你可以简单地做到这一点 -

if(any(!bool)) {
    stop("Please use the most recent met-ingest.csv file located /path/to/file/")
}

推荐阅读