[R] inconsistency in tryCatch...

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Wed Jun 22 21:21:43 CEST 2022


inline

On Wed, Jun 22, 2022 at 12:01 PM 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,

NO! You have simple defined the function -- you have not called/executed
it. This defines and calls it:

> tryCatch({function() print("fred")}(),  error = function(e) sum(1:3),
finally = sum(1:3))
[1] "fred"

Cheers,
Bert





> 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,
> AKSHAY M KULKARNI
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list