From murdoch@dunc@n @end|ng |rom gm@||@com  Sat Jun  8 14:13:55 2019
From: murdoch@dunc@n @end|ng |rom gm@||@com (Duncan Murdoch)
Date: Sat, 8 Jun 2019 08:13:55 -0400
Subject: [Rd] Determining the exit code of an "almost finished" R script
In-Reply-To: <CAPvvxJUyDVV4xe5=zPJzWs=OeD0DtSw1iWFP90LNn1apu+VCQg@mail.gmail.com>
References: <CAPvvxJUyDVV4xe5=zPJzWs=OeD0DtSw1iWFP90LNn1apu+VCQg@mail.gmail.com>
Message-ID: <03638bde-bb9b-1e67-abc1-1ab66ff153f7@gmail.com>

On 08/06/2019 7:42 a.m., Gergely Dar?czi wrote:
> Dear All,
> 
> I'm using "reg.finalizer" in a function that is to be called in R scripts
> to do some cleanup on success. I have not found a way to run the function
> only if the script run without errors, so when the exit code is expected to
> be 0.
> 
> What I've tried is checking "geterrmessage()", but unfortunately it's not
> perfect: if an error was handled with eg "tryCatch" previously, that
> message still shows up there.
> 
> Is there any better way of figuring out in "reg.finalizer" or ".Last" if
> the session run OK or exiting with !0 exit code?

Can't you just put the line to run it as the last line of your script? 
You won't get there if there was an error.

The point of reg.finalizer is to run code even if there was an error; 
your situation is much simpler.

Duncan Murdoch



[Rd] Determining the exit code of an "almost finished" R script
Duncan Murdoch