我正在尝试下面的代码,以便如果既没有"/“也没有"\”,则输出是错误的,应用程序停止,但它不工作。我看不出有什么问题。
if (grepl("/", OUTpath, fixed=TRUE)) { # mac style
OUTpath<- paste(paste(unlist(strsplit(OUTpath, "/", fixed=TRUE)), collapse="/"), "/", sep="")
} else
if (grepl("\\", OUTpath, fixed=TRUE)) { # windows style
OUTpath<- paste(paste(unlist(strsplit(OUTpath, "\\", fixed=TRUE)), collapse="\\"), "\\", sep="")
} else
if(!grepl("/", OUTpath, fixed=TRUE) || !grepl("\\", OUTpath, fixed=TRUE)){
trueFalse = FALSE
errorMessage("Unrecognized path separator in OUTpath or no path specification in PARAMS file. Cannot open connection\n
You can edit your input file and save the changes. Afterwards, stop and restart glycoPipe and upload file again")
stop("Unrecognized path separator in OUTpath\n")
}发布于 2018-04-12 08:18:25
这对我来说很有效。我删除了一个嵌套的if语句。我还对大括号做了一些改动。不太确定这是否适用于您的应用程序,也许您可以包含更多细节。
OUTpath <- 'aa' # Gives error
OUTpath <- 'aa\\aa' # Produces 'aa\\aa\\'
OUTpath <- 'aa\aa' # Produces error
OUTpath <- 'aa/aa' # Produces 'aa/aa/'
if (grepl("/", OUTpath, fixed=TRUE)) { # mac style
OUTpath<- paste(paste(unlist(strsplit(OUTpath, "/", fixed=TRUE)), collapse="/"), "/", sep="")
} else {
if (grepl("\\", OUTpath, fixed=TRUE)) { # windows style
OUTpath<- paste(paste(unlist(strsplit(OUTpath, "\\", fixed=TRUE)), collapse="\\"), "\\", sep="")
} else {
# if(!grepl("/", OUTpath, fixed=TRUE) || !grepl("\\", OUTpath, fixed=TRUE)){
trueFalse = FALSE
errorMessage("Unrecognized path separator in OUTpath or no path specification in PARAMS file. Cannot open connection\n
You can edit your input file and save the changes. Afterwards, stop and restart glycoPipe and upload file again")
stop("Unrecognized path separator in OUTpath\n")
}
}更新
您应该使用file.path()函数来使路径独立于OS。
file.path(getwd(), 'lala', 'ee')
[1] "C:/Users/Matias/Desktop/lala/ee"https://stackoverflow.com/questions/49785131
复制相似问题