tryCatch in R [Software]

posted by ElMaestro  – Denmark, 2022-09-01 12:33 (961 d 07:05 ago) – Posting: # 23247
Views: 3,408

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,697 registered users;
17 visitors (0 registered, 17 guests [including 4 identified bots]).
Forum time: 19:39 CEST (Europe/Vienna)

Do not put your faith in what statistics say until you have carefully
considered what they do not say.    William W. Watt

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