匹配括号显示无与伦比

时间:2017-03-29 14:54:00

标签: r indentation

convertToClockTime <- function(file, lag = Latency) {
  colnames(adamcorrectfile)[which(colnames(adamcorrectfile) == "X.1")] <- "Calculated.Run.Time"
  adamcorrectfile$Calculated.Run.Time <- round(adamcorrectfile$Calculated.Run.Time, digits = 0)
  adamcorrectfile$LPRS.Time <- as.POSIXct(adamcorrectfile$LPRS.Time, format = "%H:%M")


  adamcorrectfile <- adamcorrectfile[order(adamcorrectfile$LPRS.Time),]
  output <- colnames(adamcorrectfile)
  for (j in unique(adamcorrectfile$Folder)) {
    adamcorrectfile.Folder <- adamcorrectfile[which(adamcorrectfile$Folder == "print 1"),]
    adamcorrectfile.Folder$start.time <- adamcorrectfile.Folder$LPRS.Time + lag
    adamcorrectfile.Folder$end.time <- adamcorrectfile.Folder$start.time + adamcorrectfile.Folder$`Calculated.Run.Time`
    for (i in 2:nrow(adamcorrectfile)) {
      adamcorrectfile.Folder[i,"start.time"] <- max(adamcorrectfile.Folder[i,"LPRS.Time"] + 15*60, adamcorrectfile[i-1, "end.time"]
                                                    adamcorrectfile.Folder[i, "end.time"] <- adamcorrectfile.Folder[i,"start.time"] + adamcorrectfile.Folder[i,"Calculated.Run.Time"]
        }
  output <- rbind(output, adamcorrectfile.Folder)
  return(output)
      }
  }

在第1行,它表示无与伦比的开放式支架&#39; {&#39;即使它匹配。任何帮助。 R缩进是否存在一些棘手的问题,它只会因为缩进而导致出现错误

1 个答案:

答案 0 :(得分:2)

看起来问题是你没有在for循环中间关闭max函数的括号。

以下是工作代码:

convertToClockTime <- function(file, lag = Latency) {
        colnames(adamcorrectfile)[which(colnames(adamcorrectfile) == "X.1")] <- "Calculated.Run.Time"
        adamcorrectfile$Calculated.Run.Time <- round(adamcorrectfile$Calculated.Run.Time, digits = 0)
        adamcorrectfile$LPRS.Time <- as.POSIXct(adamcorrectfile$LPRS.Time, format = "%H:%M")


        adamcorrectfile <- adamcorrectfile[order(adamcorrectfile$LPRS.Time),]
        output <- colnames(adamcorrectfile)
        for (j in unique(adamcorrectfile$Folder)) {
                adamcorrectfile.Folder <- adamcorrectfile[which(adamcorrectfile$Folder == "print 1"),]
                adamcorrectfile.Folder$start.time <- adamcorrectfile.Folder$LPRS.Time + lag
                adamcorrectfile.Folder$end.time <- adamcorrectfile.Folder$start.time + adamcorrectfile.Folder$`Calculated.Run.Time`
                for (i in 2:nrow(adamcorrectfile)) {
                   adamcorrectfile.Folder[i,"start.time"] <- max(adamcorrectfile.Folder[i,"LPRS.Time"] + 15*60, adamcorrectfile[i-1, "end.time"])
                   adamcorrectfile.Folder[i, "end.time"] <- adamcorrectfile.Folder[i,"start.time"] + adamcorrectfile.Folder[i,"Calculated.Run.Time"]
                }
                output <- rbind(output, adamcorrectfile.Folder)
                return(output)
        }
        }