0

i have a for loop in a batch file which runs the same r script with different parameters and i want all output to be appended to the same file.

here is an example:

Batch Code

for %%i in ([folder name]) do (
  R CMD BATCH --slave "--args %%i" Script.R output.out
)

Script.R Code

cmdArgs = commandArgs(trailingOnly = TRUE)
cat("Args: ", cmdArgs[1], "\n")
cat("End")

I have tried using 2>&1 and it's not working.

I am using a windows machine and prefer not to redirect output from within the R script and can't user RScript, any ideas?

1 Answer 1

1

simply enclose all the output lines in the batch with additional parentheses and redirect that to a file:

(
for %%i in ([folder name]) do R CMD BATCH --slave "--args %%i" Script.R output.out
) >Output.txt

This [folder name] is only pseudo code and won't work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.