Can I tell if an R script is running under littler? -
Can I tell if an R script is running under littler? -
python has handy construct:
def do_stuff(): whatever if __name__ == "__main__": do_stuff(() so if file run command line python foo.py or ./foo.py , appropriate shebang line, __name__ variable set __main__ , file runs script. can from foo import do_stuff interactive shell or other python code , run do_stuff there. same script file acting module instead of script.
can similar in littler scripts? foo.r being:
#!/bin/env r do_stuff = function(){ whatever } if(?run r command_line?){ do_stuff() } then can source("foo.r") , define do_stuff (in default global environment, we'll gloss on bit).
one possible key presence of _ in environment when running under littler (set script name) little stronger might nice.
something should work:
#!/usr/local/bin/r --vanilla dostuff <- function(print_me) { print(print_me) } if (!interactive()) { if (exists("argv")) { if (!is.null(argv) && length(argv)>0) { dostuff(argv[1]) } } } r
Comments
Post a Comment