I have an R script that outputs TRUE or FALSE. In R, it uses a valid T / F data type, but when I return its return value in bash, it looks like a string, saying:
"[1] TRUE"
or
"[1] FALSE"
They are preceded by [1]. Also no [0], this is not a typo. Anyway, the result of this is that when I try to check the output of this Rscript to run the subsequent script, I need to do a string comparison with "[1] TRUE" as shown below, instead of comparing with "TRUE" or "1 "that feels cleaner and better.
A=$(Rscript ~/MyR.r)
echo $A
if [ "$A" == "[1] TRUE" ]; then
bash SecondScript.sh
fi
How can I do R, either print true Boolean, or Bash accept the output string and convert it to 0/1 for comparison? That is, I would rather check ...
if [ $A == TRUE ];
than
if [ "$A" == "[1] TRUE" ];
, , ?
* *
Rscript, ...
myinput <- TRUE
FunctionName <- function(test){
if (test == TRUE){
val <- TRUE
} else {
val <- FALSE
}
return(val)
}
FunctionName(myinput)