R Under development (unstable) (2025-12-16 r89184 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > message("*** devEval() - errors ...") *** devEval() - errors ... > > library("R.devices") R.devices v2.17.3 successfully loaded. See ?R.devices for help. > hpaste <- R.utils::hpaste > graphics.off() > > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > # Error handling: Incomplete image file is removed > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > path <- getDevOption("pdf", "path") > files0 <- dir(path=path) > > tryCatch({ + res <- devEval(type="pdf", name="error", { + plot(1:10) + v <- log("0") + abline(v=v) + }, onIncomplete="remove") + print(res) + }, error = function(ex) { + message("An error occurred while plotting: ", ex$message) + }) An error occurred while plotting: non-numeric argument to mathematical function > > ## Assert that any image created was removed > files <- dir(path=path) > new <- setdiff(files, files0) > if (length(new) > 0L) { + stop("Failed to remove incomplete image file: ", hpaste(sQuote(new))) + } > > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > # Error handling: Incomplete image file is renamed > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > path <- getDevOption("pdf", "path") > > ## Try many times to test unique renaming of files. > for (kk in 1:5) { + files0 <- dir(path=path) + tryCatch({ + res <- devEval(type="pdf", name="error", { + plot(1:10) + v <- log("0") + abline(v=v) + }, onIncomplete="rename") + print(res) + }, error = function(ex) { + message("An error occurred while plotting: ", ex$message) + }) + + ## Assert that any image created was removed + files <- dir(path=path) + new <- setdiff(files, files0) + if (length(new) != 1L) { + stop("Failed to rename incomplete image file") + } + cat("Incomplete image file: ", new, "\n", sep="") + } An error occurred while plotting: non-numeric argument to mathematical function Incomplete image file: error,INCOMPLETE_001.pdf An error occurred while plotting: non-numeric argument to mathematical function Incomplete image file: error,INCOMPLETE_002.pdf An error occurred while plotting: non-numeric argument to mathematical function Incomplete image file: error,INCOMPLETE_003.pdf An error occurred while plotting: non-numeric argument to mathematical function Incomplete image file: error,INCOMPLETE_004.pdf An error occurred while plotting: non-numeric argument to mathematical function Incomplete image file: error,INCOMPLETE_005.pdf > > # Sanity checks > print(devList()) named integer(0) > stopifnot(length(devList()) == 0L) > > message("*** devEval() - errors ... DONE") *** devEval() - errors ... DONE > > proc.time() user system elapsed 0.59 0.21 1.57