module_metadata: Module Metadata.

Description Usage Details Value Warning See Also Examples

Description

Access module metadata.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13

Details

When modulr loads a module file, it assigns the module's name to .__name__. A module file can discover whether or not it is running in the main scope by checking if .__name__ has value "__main__". This allows a common idiom for conditionally executing code in a module file when it is run as a script (see example). It is mainly useful when one wants to write a module file which can be executed directly as a script and alternatively declared as a dependency and used by other modules.

Value

The name of the current module scope.

Warning

Do not assign to any metadata in the workspace, because this will always mask the object of the same name in package:modulr.

See Also

define and make.

Examples

1
2
3
4
5
6
# script.R
"script" %provides% { cat("Hello World\n"); print(.__name__) }
if (.__name__ == "main") make()
# EOF
## Not run: source("script.R")
make("script")

openscienceunil/modulr documentation built on May 3, 2019, 5:49 p.m.