From kr|m|r+m| @end|ng |rom m@||box@org  Mon Aug 19 16:19:31 2019
From: kr|m|r+m| @end|ng |rom m@||box@org (=?UTF-8?Q?Kirill_M=c3=bcller?=)
Date: Mon, 19 Aug 2019 16:19:31 +0200
Subject: [Rd] Check length of logical vector also for operands of || and &&?
Message-ID: <da321aed-5d85-a206-e94f-92852da46cf9@mailbox.org>

Hi everyone


The following behavior (in R 3.6.1 and R-devel r77040) caught me by 
surprise today:

truthy <- c(TRUE, FALSE)
falsy <- c(FALSE, TRUE, FALSE)

if (truthy) "check"
#> Warning in if (truthy) "check": the condition has length > 1 and only the
#> first element will be used
#> [1] "check"
if (falsy) "check"
#> Warning in if (falsy) "check": the condition has length > 1 and only the
#> first element will be used
if (FALSE || truthy) "check"
#> [1] "check"
if (FALSE || falsy) "check"
if (truthy || FALSE) "check"
#> [1] "check"
if (falsy || FALSE) "check"

The || operator gobbles the warning about a length > 1 vector. I wonder 
if the existing checks for length 1 can be extended to the operands of 
the || and && operators. Thanks (and apologies if this has been raised 
before).


Best regards

Kirill



[Rd] Check length of logical vector also for operands of || and &&?
=?UTF-8?Q?Kirill_M=c3=bcller?=