Anonymous user
Modulinos: Difference between revisions
→{{header|R}}
Line 1,363:
=={{header|R}}==
A way to check if code is running at "top level" is to check <code>length(sys.frames())</code>. This value will be zero for a file being run with <code>Rscript</code>, the <code>--file=</code> argument, or at the command line, and will be greater than 0 in all other conditions (such as package loading or code being sourced from another file.)
<lang R>#!/usr/bin/Rscript
Line 1,373 ⟶ 1,371:
}
main <- function(
cat("Main: The meaning of life is", meaningOfLife(), "\n")
}
if (length(sys.frames()) > 0) {
args <- commandArgs(trailingOnly = FALSE)▼
▲args <- commandArgs(trailingOnly = FALSE)
▲ main(program, args)
q("no")
}</lang>
|