From c@@rd|@g@bor @end|ng |rom gm@||@com  Mon Aug 26 09:41:02 2019
From: c@@rd|@g@bor @end|ng |rom gm@||@com (=?UTF-8?B?R8OhYm9yIENzw6FyZGk=?=)
Date: Mon, 26 Aug 2019 09:41:02 +0200
Subject: [Rd] Conventions: Use of globals and main functions
In-Reply-To: <3413997.2322922.1566769574357@mail.yahoo.com>
References: <1118624909.2128031.1566706119596.ref@mail.yahoo.com>
 <1118624909.2128031.1566706119596@mail.yahoo.com>
 <CABtg=KnSVWAJ2_JNTODC5RZM+LxbZYNNJYMHzSsPiYzkHB3C8A@mail.gmail.com>
 <3413997.2322922.1566769574357@mail.yahoo.com>
Message-ID: <CABtg=KmXmOb3JJVubrf7xUp_nHW30HkOOWWbTnpU=LpuWQ2cUg@mail.gmail.com>

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 at 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 at gmail.com> wrote:
>
>
> This is what I usually put in scripts:
>
> if (is.null(sys.calls())) {
>   main()
> }
>

[...]



[Rd] Conventions: Use of globals and main functions
=?UTF-8?B?R8OhYm9yIENzw6FyZGk=?=