gpt4 book ai didi

r - 在 R 中使用 trycatch 抑制系统错误

转载 作者:行者123 更新时间:2023-12-01 13:11:19 24 4
gpt4 key购买 nike

我无法抑制该错误,尽管我的 pdf 文件正在转换为文本,但我无法抑制此错误。

 tryCatch(system(paste("\"", exe, "\" \"", dest, "\"", sep = ""), wait = T))
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
> suppressWarnings(system(paste("\"", exe, "\" \"", dest, "\"", sep = ""), wait = T))
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
>tryCatch(system(paste("\"", exe, "\" \"", dest, "\"", sep = ""), wait = T), error = function(e) e)
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
> suppressMessages(system(paste("\"", exe, "\" \"", dest, "\"", sep = ""), wait = T))
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
> tryCatch(suppressWarnings(capture.output(system(paste("\"", exe, "\" \"", dest, "\"", sep = ""), wait = T))), error = function(e) e)
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
character(0)
> tryCatch({system(paste("\"", exe, "\" \"", dest, "\"", sep = ""), wait = T)}, error = function(e) e)
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function

为什么我无法抑制它?我怎样才能摆脱这个错误?谢谢。

编辑

silent=TRUEfunction(e){invisible(e)}
tryCatch(system(paste("\"", exe, "\" \"", dest, "\"", sep = ""), wait = T), error = function(e){invisible(e)})
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
> try(system(paste("\"", exe, "\" \"", dest, "\"", sep = ""), wait = T),silent=TRUE)
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function
Syntax Error: Missing or invalid 'Bounds' entry in stitching function

已编辑

它停止了错误,但它也停止了功能,pdf 文件不会因此转换为文本。
tryCatch(system2(paste("\"", exe, "\" \"", dest, "\"", sep = ""), wait = TRUE, 
stdout=TRUE, stderr=TRUE),
error=function(err) NA)
[1] NA

源代码
dest=paste("C:/wamp/www/LU/my/pdffiles",file_list[i],sep="/")
exe <- "C:\\Program Files\\xpdfbin-win-3.03\\bin32\\pdftotext.exe"
try(system(paste("\"", exe, "\" \"", dest, "\"", sep = ""), wait = TRUE),
silent=TRUE)

最佳答案

通常一个人会写

tryCatch({
system("xyz")
}, error=function(err) {
## do something with 'err', then maybe throw it again stop(err)
## or providing an alternative return value
NA
})

所以
> xx = tryCatch(stop("oops"), error=function(err) NA)
> xx
[1] NA

但似乎 system() 抛出了一些错误不能以这种方式被捕获。
> xx = tryCatch(system("foobar"), error=function(err) NA)
sh: 1: foobar: not found

某事可能完成的提示来自 xx 的值:
> xx
[1] 127

帮助页面首先将我们指向 system2()相反,我们看到的地方
If 'stdout = TRUE' or 'stderr = TRUE', a character vector giving
the output of the command, one line per character string. (Output
lines of more than 8095 bytes will be split.) If the command
could not be run an R error is generated.

果然
> tryCatch(system2("foobar", stdout=TRUE, stderr=TRUE), error=function(err) NA)
[1] NA

关于r - 在 R 中使用 trycatch 抑制系统错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25991973/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com