The title says it all. The objective is to have two simple ways to source some code, say func.R, containing a function. Calling R CMD BATCH func.R initializes the function and evaluates is. Within a session, issuing source("func.R") simply initializes the function.
Any idea?
views:
177answers:
3
                +2 
                A: 
                
                
              You could pass arguments into R, and if an argument is present run main(). More on arguments here: http://yangfeng.wordpress.com/2009/09/03/including-arguments-in-r-cmd-batch-mode/
                  Vince
                   2010-06-03 17:19:43
                
              I voted the other answer, but I didn't know you could pass arguments from the command line either. That's helpful.
                  gappy
                   2010-06-06 02:28:56
                Since about the beginning of 2009 it's been possible to run R scripts with a shebang line, e.g. `#!/usr/bin/Rscript --vanilla` directly from the command line: e.g. run `chmod 700 my_script.r` to make it executable, and then you can run the script with `./my_script.r` (within the script you read arguments the same way as in the link above, by `args=(commandArgs(TRUE))`
                  Michael Dunn
                   2010-06-20 11:24:00
                Excellent, I had no idea this existed. I think this will change the way I write R.
                  Vince
                   2010-06-03 17:46:43
                With the Rscript shebang line and this our R scripts will be more pythonic than ever before!
                  Michael Dunn
                   2010-06-20 11:25:22