As I said in my comment, I would use Rscript instead of R CMD BATCH : Rscript myscript. R batch. Csv where myscript.
R contains: args.
As I said in my comment, I would use Rscript instead of R CMD BATCH: Rscript myscript. R batch. Csv where myscript.
R contains: args.
With this exact syntax, I get "Error: could not find function "batch_args". If I put a print(args) statement, "batch. Csv" is there, however.
– Benjamin Jan 26 at 18:53 I don't mind using Rscript, but can I get the output written to a file similar to R CMD BATCH --slave? Why is Rscript better? – Benjamin Jan 26 at 18:59 @Benjamin: I think you copied and/or pasted something wrong.
There's no way the code I posted would give you that error because that error requires something like batch_args(). – Joshua Ulrich Jan 26 at 19:01 Thanks for your help, found error later in the code. – Benjamin Jan 26 at 19:22 2 If you want to get the stdout redirected to a file, use Rscript myscript.
R batch. Csv > myscript.Rout. Alternatively you can use sink().
– Charles Jan 26 at 20:46.
The filename is in there, in the commandArgs() function, you just have to work out how to get it out. Code and error messages are handy. That's not a problem if the only extra argument is a filename, you know its position.
What will confuse you is when you start having more complex argument passing. You're also complicating things with passing 'fn=foo. Csv'.
Just pass the filename and assign it to fn in your script. If you really want to use eval you probably need to quote your filename, thus myscript. R is: ca = commandArgs(trailingOnly=TRUE) eval(parse(text=ca)) print(read.
Csv(fn)) and run thus: R --slave "--args fn='batch. Csv'" R A B C 1 1 2 3 2 6 8 3 Where batch. Csv is a simple csv file.
You could do a loop over "ca" in your script and eval everything.It's slightly dangerous though, since you could easily break basic functionality. Personally I'd loop over ca, look for name=value pairs for a known set of names, and set them. Basically implementing getopt, but someone has probably done that already...
Almost works, but breaks when trying to do read. Table because "batch. Csv" is not recognized as a proper filename but as string.
I though giving it the full path might help, but then it breaks because of spaces. Currently, I run it from the directory where all files are located (.r, . Txt and .
Csv). – Benjamin Jan 26 at 18:41 There's no such thing as a 'proper filename'. R stores filenames in strings.
Fn="batch. Csv"; read. Csv(fn) will read from the file batch.csv.
– Spacedman Jan 26 at 18:44 okay, my example now reads from a csv file as proof-of-concept. – Spacedman Jan 26 at 18:46 When I run the exact syntax from above R --slave "--args fn='batch. Csv'" R, I get the warning unknown option "--args fn='batch.
Csv'". – Benjamin Jan 26 at 18:48 1 I don't know how COMMAND.COM bothers to treat single or double quotes. Second thing I do on Windows installs is to install Cygwin.
First thing is install Firefox in order to get Cygwin. – Spacedman Jan 26 at 22:50.
Besides using Rscript (as Josh said) you should also use the CRAN packages getopt or optparse as they were written for this very purpose.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.