Help in swirl lesson 8 logic TRUE && c (TRUE, FALSE, FALSE ) Error in TRUE && c(TRUE, FALSE, FALSE) : 'length = 3' in coercion to 'logical(1)

Error in TRUE && c(TRUE, FALSE, FALSE) :
'length = 3' in coercion to 'logical(1)

I'm getting this error anytime I try to work on the posit cloud swirl course lesson 8 on logic

It seems to be a system glitch, is there anyway to go around because I can't get to the next lesson

1 Like



in R console and the help page will give you the answer:

& and && indicate logical AND and | and || indicate logical OR. The shorter forms performs elementwise comparisons in much the same way as arithmetic operators. The longer forms evaluates left to right, proceeding only until the result is determined. The longer form is appropriate for programming control-flow and typically preferred in if clauses.

Using vectors of more than one element in && or || will give an error.

1 Like

Thanks for this response. After running the ?'&&', I see that using && would report as an error, but how do I go past the particular step in the course. I'm required to replicate a particular string and any deviation means the course wouldn't accept it, rather it would asking me to type the exact code, meanwhile the exact code is an error. This is my dilemma, any further help?


1 Like

it's a back quote `, not a quotation ', please note the difference.

Still the same thing, I think I'll just skip the topic for now

1 Like

Hey, did you happen to figure it out? It bothers me that I can't get past this step lol

1 Like

the very same to me...updated my R version to 4.3.1; then updated RStudio and cannot pass through this "question" in Lesson 8 "Logic"...sad sad :frowning:

&& and || are operators for single logical vectors/values
valid: TRUE && TRUE || FALSE
invalid: TRUE/FALSE && (or ||) c(TRUE, FALSE,...)
You have to

  • use all() / any() when you want to "mix" multiple values logical vector with && || operators
    TRUE && (all(c (TRUE, FALSE, FALSE ))
    TRUE && (any(c (TRUE, FALSE, FALSE ))
  • use single | or & operators.
    [1] TRUE TRUE

Have fun!

I couldn't solve it so I let it be, it seems it was due to system update and there's no going around it.

Is it possible to have it "old way" with warning somehow in R 4.3 ?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.