【问题标题】:Warning Message when using if()使用 if() 时的警告消息
【发布时间】:2017-02-06 23:18:21
【问题描述】:

我正在尝试对多个文件执行一个功能,我正在使用这个:

require(readxl);
require(MESS);
final_df <- NULL;
for(i in CHI.Files){
  PPeakD <- read_excel(paste0('/Users/andrewmclean/Dropbox/Research/Andrew/
                           LungStudyOutput - Whole case/',i), sheet = "Ppeak");
  PPeakD <- PPeakD[c(4,5)]
  colnames(PPeakD)<-c("Time","PPeak")
  PPeakD <- PPeakD[c(which(PPeak$PPeak>0)),]

  PEEP <- read_excel(paste0("~/Dropbox/Research/Andrew/
                     LungStudyOutput - Whole case/",i), 
                     sheet = "PEEP")
  PEEP <- PEEP[c(4,5)]
  colnames(PEEP)<-c("Time","PEEP")
  PEEP <- PEEP[c(which(PEEP$PEEP>0)),]

  PPeakAdj <- CHI.Files.frame(approx(PPeak$Time, PPeak$PPeak, 
                                     xout = PEEP$Time, method = "linear", rule = 2))
  colnames(PPeakAdj)<-c("Time","PPeakAdj")

  DrivP <- CHI.Files.frame((PPeakAdj$Time),((c(PPeakAdj$PPeakAdj)) - (c(PEEP$PEEP))))
  colnames(DrivP) <- c("Time", "DrivP")
  final_df <- rbind(final_df,DrivP)
}

但是,当我这样做时,我只会收到以下消息:

In addition: Warning messages:
1: In if (!file.exists(path)) { :
  the condition has length > 1 and only the first element will be used
2: In if (!is_absolute_path(path)) paste0(" in current working directory ('",  :
  the condition has length > 1 and only the first element will be used

寻找任何关于我做错了什么的建议?

谢谢

编辑: 使@Jonathan Carroll 的更正错误代码如下所示:

 Error: '/Users/andrewmclean/Dropbox/Research/Andrew/
                           LungStudyOutput - Whole case/013234-1.xls/Users/andrewmclean/Dropbox/Research/Andrew/
                           LungStudyOutput - Whole case/006538-1.xls/Users/andrewmclean/Dropbox/Research/Andrew/
                           LungStudyOutput - Whole case/000478-1.xls/Users/andrewmclean/Dropbox/Research/Andrew/
                           LungStudyOutput - Whole case/025396-1.xls/Users/andrewmclean/Dropbox/Research/Andrew/
                           LungStudyOutput - Whole case/045495-1.xls/Users/andrewmclean/Dropbox/Research/Andrew/
                           LungStudyOutput - Whole case/000443-1.xls/Users/andrewmclean/Dropbox/Research/Andrew/
                           LungStudyOutput - Whole case/020462-1.xls/Users/andrewmclean/Dropbox/Research/Andrew/
                           LungStudyOutput - Whole case/080677-1.xls/Users/andrewmclean/Dropbox/Research/Andrew/

In addition: Warning messages:
1: In if (!file.exists(path)) { :
  the condition has length > 1 and only the first element will be used
2: In if (!is_absolute_path(path)) paste0(" in current working directory ('",  :
  the condition has length > 1 and only the first element will be used

【问题讨论】:

  • 我不知道CHI.Files 中有什么,但从它的外观来看,不仅仅是一个值。在循环之前注释掉循环,看看你是否可以让它为单个文件工作。在每一步检查变量的内容,确保它们是你所想的。
  • 是的,它没有跳出循环。我认为问题在于我的数据被“平衡”了,因此它试图将太多数据放入......

标签: r function loops


【解决方案1】:

据推测,它的内容周围应该有一个paste,因为它目前正试图提供太多参数

PEEP <- read_excel("~/Dropbox/Research/Andrew/
                 LungStudyOutput - Whole case/",CHI.Files[i], sep='', 
                 sheet = "PEEP")

【讨论】:

  • 我没有注意到 - 谢谢!!我已经更新了它,但仍然收到类似的消息:此外:警告消息:1:在 if (!file.exists(path)) { 中:条件的长度 > 1,并且只会使用第一个元素2:在 if (!is_absolute_path(path)) paste0(" in current working directory ('", : 条件长度 > 1 并且只使用第一个元素}
猜你喜欢
  • 1970-01-01
  • 2018-05-25
  • 1970-01-01
  • 2023-03-14
  • 1970-01-01
  • 1970-01-01
  • 2012-01-17
  • 1970-01-01
  • 2019-07-03
相关资源
最近更新 更多