Skip to content
Prev 57377 / 63424 Next

Conventions: Use of globals and main functions

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()
}

This is mostly equivalent to the Python idiom. It the script runs from
Rscript, then it will run main(). It also lets you source() the
script, and debug its functions, test them, etc. It works best if all
the code in the script is organized into functions.

Gabor

On Sun, Aug 25, 2019 at 6:11 AM Cyclic Group Z_1 via R-devel
<r-devel at r-project.org> wrote:

Thread (21 messages)

Cyclic Group Z_1 Conventions: Use of globals and main functions Aug 24 Gábor Csárdi Conventions: Use of globals and main functions Aug 24 Duncan Murdoch Conventions: Use of globals and main functions Aug 25 Cyclic Group Z_1 Conventions: Use of globals and main functions Aug 25 Cyclic Group Z_1 Conventions: Use of globals and main functions Aug 25 Duncan Murdoch Conventions: Use of globals and main functions Aug 25 Gábor Csárdi Conventions: Use of globals and main functions Aug 26 Cyclic Group Z_1 Conventions: Use of globals and main functions Aug 26 William Dunlap Conventions: Use of globals and main functions Aug 26 Duncan Murdoch Conventions: Use of globals and main functions Aug 26 Martin Maechler Conventions: Use of globals and main functions Aug 27 Peter Meissner Conventions: Use of globals and main functions Aug 27 Abby Spurdle Conventions: Use of globals and main functions Aug 27 Abby Spurdle Conventions: Use of globals and main functions Aug 27 Henrik Bengtsson Conventions: Use of globals and main functions Aug 27 Cyclic Group Z_1 Conventions: Use of globals and main functions Aug 27 Cyclic Group Z_1 Conventions: Use of globals and main functions Aug 27 Peter Meissner Conventions: Use of globals and main functions Aug 28 Cyclic Group Z_1 Conventions: Use of globals and main functions Aug 28 Peter Meissner Conventions: Use of globals and main functions Aug 28 Cyclic Group Z_1 Conventions: Use of globals and main functions Aug 28