I have the following bash script in which the R script is called
#!/bin/bash
declare -x a=33
declare -x b=1
declare -x c=0
Rscript --vanilla MWE.R $a $b $c
echo $a $b $c
I want to change bash variables in an R script and return their changed values in a bash script, because then I pass the changed variables somewhere else. R script is
args = commandArgs(trailingOnly=TRUE)
Rb = as.numeric(args[2])
Rc = as.numeric(args[3])
Rb = Rb + 1
Rc = Rc + 1
args[2]=Rb
args[3]=Rc
print(c(args[1],args[2],args[3]))
However, the conclusion printand, echoaccordingly:
[1] "33" "2" "1"
33 1 0
which shows that new values are not passed from R to bash. What am I doing wrong?
source
share