Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7928013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:37:20+00:00 2026-06-03T19:37:20+00:00

I have an R script that outputs TRUE or FALSE. In R, it’s using

  • 0

I have an R script that outputs TRUE or FALSE. In R, it’s using a bona fide T/F data type, but when I echo its return value to bash, it seems to be a string, saying:

"[1] TRUE"

or

"[1] FALSE"

They are both preceded by [1]. Neither is [0], that is not a typo. Anyway, the result of this is what when I try to test on the output of this Rscript to run a subsequent script, I have to do string comparison to "[1] TRUE" as below, instead of comparing to "TRUE" or "1" which feels cleaner and better.

A=$(Rscript ~/MyR.r)
echo $A
if [ "$A" == "[1] TRUE" ]; then
    bash SecondScript.sh
fi

How can I make R either output a true Boolean, or Bash accept the output string and convert it to 0/1 for comparison? That is, I’d rather test for…

if [ $A == TRUE ];

than

if [ "$A" == "[1] TRUE" ];

Is that possible, or should I be happy with this, how it is, which works?

*** UPDATE ***

Here’s the minimalized version of the Rscript that generates this…

myinput <- TRUE #or FALSE

FunctionName <- function(test){
  if (test == TRUE){
    val <- TRUE
  } else {
    val <- FALSE
  }
  return(val)
}

FunctionName(myinput)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:37:24+00:00Added an answer on June 3, 2026 at 7:37 pm

    Instead of using either print() or the implicit print()-ing that occurs when an object name is offered to the R interpreter, you should be using cat() which will not prepend the “[1] ” in front of either TRUE or FALSE. If you want 0/1, then use cat(as.numeric(.)). Try this instead:

    myinput <- TRUE #or FALSE
    FunctionName <- function(test){
       if (test == TRUE){
                  val <- TRUE
                        } else {
                  val <- FALSE
                }
       cat(as.numeric(val))
    }
    FunctionName(myinput)
    

    If you needed that value for further processing you could also use this:

    cat(as.numeric(val)); invisible(val)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP script (fetchData.php) that fetches some data and outputs it to
I have a script that connects to SQL Server 2005 default instance. But I'm
I have a script that generates images from text using PHP. It's working fine
I installed wkhtmltopdf using sudo apt-get install wkhtmltopdf I have a php script that
I have a question. I'm using a script that will check the domain in
I have a script that generates two lines as output each time. I'm really
I have a script that creates an image and calls imagepng to output it
Does anyone have a script for logparser that will output a graph for daily
I have a script (worker.py) that prints unbuffered output in the form... 1 2
I have a script that checks something on my PC every 5 minutes and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.