[R] inconsistency in tryCatch...

akshay kulkarni @k@h@y_e4 @end|ng |rom hotm@||@com
Wed Jun 22 21:36:27 CEST 2022

Dear Jeff,
               Thanks! I think it is an idiosyncrasy of tryCatch? The other arguments like "error" doesn't need to be assigned to a call right? Just the definition would be sufficient, i think?

Yours sincerely,
From: Jeff Newmiller <jdnewmil using dcn.davis.ca.us>
Sent: Thursday, June 23, 2022 12:53 AM
To: r-help using r-project.org <r-help using r-project.org>; akshay kulkarni <akshay_e4 using hotmail.com>; R help Mailing list <r-help using r-project.org>
Subject: Re: [R] inconsistency in tryCatch...

You defined a function. You did not call the function. tryCatch returned the object you defined. So the interactive console printed the object returned.

Invoking the "function" function does not call the defined function for you. Try:

tryCatch((function() print("fred"))(), error = function(e) sum(1:3), finally = sum(1:3))

On June 22, 2022 12:00:38 PM PDT, akshay kulkarni <akshay_e4 using hotmail.com> wrote:
>Dear members,
>                          I have the following code:
>        > tryCatch(function() print("fred"),  error = function(e) sum(1:3), finally = sum(1:3))
>         function() print("fred")
>The expected output from the tryCatch call should be to print "fred" to the console, and exit, but as seen above, it is outputting
>          function() print("fred")
>Can you people please shed some light on what is happening?
>thanking you,
>Yours sincerely,
>       [[alternative HTML version deleted]]
>R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

Sent from my phone. Please excuse my brevity.

	[[alternative HTML version deleted]]

More information about the R-help mailing list