tryCatch in R [Software]
Hi ElMaestro,
OK, a second attempt with already mentioned processx package
❝ It works with the hamburger example but not when I invoke gcc :
❝
❝ > tryCatch(
❝ + {
❝ + a <- system("gcc -O2 -Wall Tester301.c -o T301", intern=T)
❝ + },
❝ + error = function(cond) {
❝ + a <<- cond
❝ + }
❝ + )
❝ cc1: fatal error: Tester301.c: No such file or directory
❝ compilation terminated.
❝ Warning message:
❝ In system("gcc -O2 -Wall Tester301.c -o T301", intern = T) :
❝ > a
❝ character(0)
❝ attr(,"status")
❝ [1] 1
OK, a second attempt with already mentioned processx package
tryCatchHamburger <- function(string) {
# initializing to prevent 'a' to go higher closures in case of error
a <- NULL
tryCatch({
a <- processx::run(string, stderr = NULL)
},
error = function(cond) {
a <<- cond
})
a
}
b <- tryCatchHamburger("Hamburger")
class(b)
# [1] "c_error" "rlib_error_3_0" "rlib_error" "error" "condition"
print(b$parent$message)
# [1] "cannot start processx process 'gcc -O2 -Wall Tester301.c -o T301' (system error 2, No such file or directory) @unix/processx.c:613 (processx_exec)"
c <- tryCatchHamburger("gcc -O2 -Wall Tester301.c -o T301")
class(c)
# [1] "c_error" "rlib_error_3_0" "rlib_error" "error" "condition"
print(c$parent$message)
# [1] "cannot start processx process 'gcc -O2 -Wall Tester301.c -o T301' (system error 2, No such file or directory) @unix/processx.c:613 (processx_exec)"
—
Kind regards,
Mittyri
Kind regards,
Mittyri
Complete thread:
- system and system2 in R ElMaestro 2022-08-29 22:29 [Software]
- system and system2 in R Helmut 2022-08-30 01:10
- system and system2 in R ElMaestro 2022-08-30 08:52
- system and system2 in R Helmut 2022-08-30 11:25
- processx package mittyri 2022-08-31 17:50
- system and system2 in R ElMaestro 2022-08-30 08:52
- tryCatch in R mittyri 2022-08-31 17:53
- tryCatch in R ElMaestro 2022-09-01 10:33
- tryCatch in Rmittyri 2022-09-01 14:07
- tryCatch in R ElMaestro 2022-09-01 10:33
- system and system2 in R Helmut 2022-08-30 01:10