0

I have a R script and I would like to pass some filenames/parameters to my Rscript and to execute it from a terminal. I used this command:

fileA='aaaa.txt'
fileB='bbbb.txt'
n=100
string='hello'
R CMD BATCH --vanilla '--args $fileA $fileB $n $string' Rscript_file.R

I added this line in my Rscript_file.R file:

args <- commandArgs(trailingonly=TRUE)

but I got this error:

> args <- commandArgs(trailingonly=TRUE)
Error in commandArgs(trailingonly = TRUE) : 
  unused argument (trailingonly = TRUE)
Execution halted

Any ideas? thanks

pingu87
  • 103
  • 6
  • you use the wrong argument. It needs to be with a capital 'O'. commandArgs(trailingOnly = TRUE) – Jagge Oct 26 '21 at 09:17
  • The argument is `trailingOnly` (with a capital O). – user2554330 Oct 26 '21 at 09:17
  • thansk a lot! but it seems it doesn't recognised the strings/value of each variable. I got this error: 'In file(file, "r") : cannot open file '$fileA': No such file or directory' Any adieas? – pingu87 Oct 26 '21 at 09:49
  • That error seems to be about something different than the current question and the current question lacks the details to debug it. Therefore, I'm voting to close this as a typo question. – teunbrand Oct 26 '21 at 22:06

0 Answers0