tryCatch in R [Software]

posted by ElMaestro  – Denmark, 2022-09-01 12:33 (94 d 00:42 ago) – Posting: # 23247
Views: 471

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
22,428 posts in 4,694 threads, 1,598 registered users;
19 visitors (0 registered, 19 guests [including 6 identified bots]).
Forum time: 12:15 CET (Europe/Vienna)

Operational hectic replaces
intellectual calms.    Alexander Huiskes

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