tryCatch in R [Software]

posted by ElMaestro  – Denmark, 2022-09-01 12:33 (775 d 01:58 ago) – Posting: # 23247
Views: 2,540

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,258 posts in 4,886 threads, 1,671 registered users;
69 visitors (0 registered, 69 guests [including 7 identified bots]).
Forum time: 14:32 CEST (Europe/Vienna)

Tortured data will confess to anything.    Fredric Menger

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