Access module metadata.
.__name__ .__version__ .__namespace__ .__initials__ .__final__ .__file__ .__path__
The name of the current module scope.
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.
Do not assign to any metadata in the workspace, because
this will always mask the object of the same name in package:modulr
.
# script.R "script" %provides% { cat("Hello World\n"); print(.__name__) } if (.__name__ == "main") make() # EOF ## Not run: source("script.R") make("script")#> Hello World #> [1] "script"