R 跳过列表错误
Skip list errors with R
我有一个 'for',它试图加载多个文件,但是,当打开这些文件中的任何一个时,它会出现以下错误:
Error: Evaluation error: zip file 'V:/Planejamento/2021/Programação/04. Abr/Balun/~$Schedule Balun 0804.xlsx' cannot be opened.
有什么方法可以让列表中的搜索和录音继续只忽略那些打开的?
代码:
for(i in i:length(arquivo_caracter)){
master[[i]] <- data.frame(read_excel(arquivo_caracter[i], sheet = "Master", skip = 0, .name_repair = "minimal"))
dados[[i]] <- data.frame(read_excel(arquivo_caracter[i], sheet = "Dados",skip = 1, .name_repair = "minimal"))
}
按照评论中的建议,tryCatch
:
arquivo_caracter <- list("test1.xls","test2.xls")
for(i in 1:length(arquivo_caracter)){
tryCatch({
master[[i]] <- data.frame(read_excel(arquivo_caracter[i], sheet = "Master", skip = 0, .name_repair = "minimal"))
dados[[i]] <- data.frame(read_excel(arquivo_caracter[i], sheet = "Dados",skip = 1, .name_repair = "minimal"))},
error = function(e) {warning(paste("Couldn't open",arquivo_caracter[i]))}
)
}
#Warning messages:
#1: In value[[3L]](cond) : Couldn't open test1.xls
#2: In value[[3L]](cond) : Couldn't open test2.xls
我有一个 'for',它试图加载多个文件,但是,当打开这些文件中的任何一个时,它会出现以下错误:
Error: Evaluation error: zip file 'V:/Planejamento/2021/Programação/04. Abr/Balun/~$Schedule Balun 0804.xlsx' cannot be opened.
有什么方法可以让列表中的搜索和录音继续只忽略那些打开的?
代码:
for(i in i:length(arquivo_caracter)){
master[[i]] <- data.frame(read_excel(arquivo_caracter[i], sheet = "Master", skip = 0, .name_repair = "minimal"))
dados[[i]] <- data.frame(read_excel(arquivo_caracter[i], sheet = "Dados",skip = 1, .name_repair = "minimal"))
}
按照评论中的建议,tryCatch
:
arquivo_caracter <- list("test1.xls","test2.xls")
for(i in 1:length(arquivo_caracter)){
tryCatch({
master[[i]] <- data.frame(read_excel(arquivo_caracter[i], sheet = "Master", skip = 0, .name_repair = "minimal"))
dados[[i]] <- data.frame(read_excel(arquivo_caracter[i], sheet = "Dados",skip = 1, .name_repair = "minimal"))},
error = function(e) {warning(paste("Couldn't open",arquivo_caracter[i]))}
)
}
#Warning messages:
#1: In value[[3L]](cond) : Couldn't open test1.xls
#2: In value[[3L]](cond) : Couldn't open test2.xls