[Rd] Conventions: Use of globals and main functions
Gábor Csárdi
c@@rd|@g@bor @end|ng |rom gm@||@com
Mon Aug 26 09:41:02 CEST 2019
That is unfortunately wrong, though. Whether the script runs as "main"
and whether R is in interactive mode are independent properties. I
guess most of the time it works, because _usually_ you run the whole
script (main()) in non-interactive mode, and source() it in
interactive mode, but this is not necessarily always the case, e.g.
you might want to source() in non-interactive mode to run some tests,
or use the functions of the script in another script, in which cases
you don't want to run main().
G.
On Sun, Aug 25, 2019 at 11:47 PM Cyclic Group Z_1
<cyclicgroup-z1 using yahoo.com> wrote:
>
> This seems like a nice idiom; I've seen others use
> if(!interactive()){
> main()
> }
> to a similar effect.
>
> Best,
> CG
>
> On Sunday, August 25, 2019, 01:16:06 AM CDT, Gábor Csárdi <csardi.gabor using gmail.com> wrote:
>
>
> This is what I usually put in scripts:
>
> if (is.null(sys.calls())) {
> main()
> }
>
[...]
More information about the R-devel
mailing list