tryCatch in R [Software]

posted by ElMaestro  – Denmark, 2022-09-01 12:33 (1022 d 17:07 ago) – Posting: # 23247
Views: 4,115

Hi mittyri,

❝ maybe I misunderstood your goal but won't

tryCatch(

❝   {   
❝     a <- system(command="hamburger", intern = T)
❝   }, 
❝   error = function(cond) {
❝     a <<- cond
❝   }

❝ )

❝ work?


Thank you for the proposal. :-)
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) :
  running command 'gcc -O2 -Wall Tester301.c -o T301' had status 1

> a
character(0)
attr(,"status")
[1] 1


So given the difference in behaviour I have a feeling this is about stderr and stdout. My own understanding of these concepts is rudimentary, to say the least.
R must be listening on both channels, so to say. Need to play a little more around with the ">" and ">2" commandline switches.

Pass or fail!
ElMaestro

Complete thread:

UA Flag
Activity
 Admin contact
23,424 posts in 4,927 threads, 1,676 registered users;
43 visitors (0 registered, 43 guests [including 9 identified bots]).
Forum time: 05:40 CEST (Europe/Vienna)

Complex, statistically improbable things are by their nature
more difficult to explain than
simple, statistically probable things.    Richard Dawkins

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5