I am used to seeing a function like this:> function_name <- function(arg_1, arg_2, ...) {
Function body
}
Where would I find documentation on building functions of the form of tryCatch?
In the form I am used to, the function would look like this:
tryCatch <- function(){
print("fred")
}
tryCatch()
Tim
-----Original Message-----
From: R-help <r-help-bounces at r-project.org> On Behalf Of Jeff Newmiller
Sent: Wednesday, June 22, 2022 3:24 PM
To: r-help at r-project.org; akshay kulkarni <akshay_e4 at hotmail.com>; R
help Mailing list <r-help at r-project.org>
Subject: Re: [R] inconsistency in tryCatch...
[External Email]
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 at
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,
>AKSHAY M KULKARNI
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailm
>an_listinfo_r-2Dhelp&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRz
>sn7AkP-g&m=4GOIwQQ_5zpqVjTnLYhmyFiVnTjVbTaENrDP6E3yyYsFz0UsfGP3b8k4vIW5
>G8Od&s=miLGRDrHT2Mq-cL9E3qEBX6MDiNcxeNASJxGBFYRFRA&e>PLEASE do
read the posting guide
>https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org
>_posting-2Dguide.html&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsR
>zsn7AkP-g&m=4GOIwQQ_5zpqVjTnLYhmyFiVnTjVbTaENrDP6E3yyYsFz0UsfGP3b8k4vIW
>5G8Od&s=rwDSAcNw3na2O_NBsF6rl4XQL03_s3n5dXuEnpxcYRM&e>and provide
commented, minimal, self-contained, reproducible code.
--
Sent from my phone. Please excuse my brevity.
______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=4GOIwQQ_5zpqVjTnLYhmyFiVnTjVbTaENrDP6E3yyYsFz0UsfGP3b8k4vIW5G8Od&s=miLGRDrHT2Mq-cL9E3qEBX6MDiNcxeNASJxGBFYRFRA&ePLEASE
do read the posting guide
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=4GOIwQQ_5zpqVjTnLYhmyFiVnTjVbTaENrDP6E3yyYsFz0UsfGP3b8k4vIW5G8Od&s=rwDSAcNw3na2O_NBsF6rl4XQL03_s3n5dXuEnpxcYRM&eand
provide commented, minimal, self-contained, reproducible code.