How can I suppress the line numbers output using R CMD BATCH?
Use cat
instead of print
if you want to suppress the line numbers ([1]
, [2]
, ...) in the output.
I think you are also going to want to pass command line arguments. I think the easiest way to do that is to create a file with the RScript shebang:
For example, create a file called args.r
:
#!/usr/bin/env Rscript
args <- commandArgs(TRUE)
cat(args, sep = "\n")
Make it executable with chmod +x args.r
and then you can run it with ./args.r ARG1 ARG2
FWIW, passing command line parameters with the R CMD BATCH ...
syntax is a pain. Here is how you do it: R CMD BATCH "--args ARG1 ARG2" args.r
Note the quotes. More discussion here
UPDATE: changed shebang line above from #!/usr/bin/Rscript
to #!/usr/bin/env Rscript
in response to @mbq's comment (thanks!)
Yes, mbq is right -- use Rscript
, or, if it floats your boat, littler:
$ cat /tmp/tommy.r
#!/usr/bin/r
cat("hello world\n")
print(argv[])
$ /tmp/tommy.r a b c
hello world
[1] "a" "b" "c"
$
You probably want to look at CRAN packages getopt and optparse for argument-parsing as you'd do in other scripting languages/
Use commandArgs(TRUE)
and run your script with Rscript
.
EDIT: Ok, I've misread your question. David has it right.