is.main | R Documentation |
Determine if a program is the main program, or if a program was run from a shell.
is.main()
from.shell()
If no scripts are being \sourcelink-ed, then is.main()
will be
TRUE
, and FALSE
otherwise.
If is.main()
is TRUE
and R was invoked with the command-line
arguments -f FILE, --file=FILE, or -e
EXPR, then from.shell()
will be TRUE
, and FALSE
otherwise.
TRUE
or FALSE
.
FILE.R <- tempfile(fileext = ".R")
@R_PACKAGE_NAME@:::.writeCode({
@R_PACKAGE_NAME@:::.withAutoprint({
from.shell()
is.main()
}, spaced = TRUE, verbose = FALSE,
prompt.echo = "FILE.R> ", continue.echo = "FILE.R+ ")
}, FILE.R)
@R_PACKAGE_NAME@:::.Rscript(c(
"--default-packages=@R_PACKAGE_NAME@", "--vanilla",
FILE.R
), show.command = FALSE, show.output.on.console = TRUE)
source(FILE.R, verbose = FALSE)
@R_PACKAGE_NAME@:::.Rscript(c(
"--default-packages=@R_PACKAGE_NAME@", "--vanilla",
"-e", "cat(\"\n> from.shell()\\n\")",
"-e", "from.shell()",
"-e", "cat(\"\n> is.main()\\n\")",
"-e", "is.main()",
"-e", "cat(\"\n> source(commandArgs(trailingOnly = TRUE))\\n\")",
"-e", "source(commandArgs(trailingOnly = TRUE))", FILE.R
), show.command = FALSE, show.output.on.console = TRUE)
unlink(FILE.R)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.