----------- FAILURE REPORT --------------
--- failure: the condition has length > 1 ---
--- srcref ---
:
--- package (from environment) ---
daewr
--- call from context ---
ihstep(y, x, m, c)
--- call from argument ---
if (t1 == "I" & t2 == "(") {
iquad = TRUE
}
--- R stacktrace ---
where 1: ihstep(y, x, m, c)
where 2: eval(expr, pf)
where 3: eval(expr, pf)
where 4: withVisible(eval(expr, pf))
where 5: evalVis(expr)
where 6: capture.output(res <- ihstep(y, x, m, c))
where 7: withCallingHandlers(expr, warning = function(w)
invokeRestart("muffleWarning"))
where 8: suppressWarnings(invisible(capture.output(res <- ihstep(y, x,
m, c))))
where 9: HierAFS(x$y, x[, -6], m = 5, c = 0, step = 4, nm1 = FALSE)
--- value of length: 3 type: logical ---
[1] FALSE FALSE FALSE
--- function from context ---
function (y, des, m, c)
{
lin <- colnames(des)
values <- c("A", "B", "C", "D", "E", "F", "G", "H", "I",
"J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
"U", "V", "W", "X", "Y", "Z")
repl <- c("I(A^2)", "I(B^2)", "I(C^2)", "I(D^2)", "I(E^2)",
"I(F^2)", "I(G^2)", "I(H^2)", "I(I^2)", "I(J^2)", "I(K^2)",
"I(L^2)", "I(M^2)", "I(N^2)", "I(O^2)", "I(P^2)", "I(Q^2)",
"I(R^2)", "I(S^2)", "I(T^2)", "I(U^2)", "I(V^2)", "I(W^2)",
"I(X^2)", "I(Y^2)", "I(Z^2)")
repl.tab <- cbind(values, repl)
if (m == 0) {
quad <- character()
}
else {
indx <- rep(0, m)
for (i in 1:m) {
indx[i] <- match(lin[i], repl.tab[, 1], nomatch = 0)
}
quad <- rep("A", m)
for (i in 1:m) {
quad[i] <- lin[i]
}
quad[indx != 0] <- repl.tab[indx, 2]
quad <- paste(quad, collapse = "+")
}
dat <- data.frame(y = y, des)
lm1 <- lm(y ~ (.)^2, data = dat)
mm <- model.matrix(lm1)
fact <- colnames(mm)
fact <- fact[-1]
fact <- paste(fact, collapse = "+")
mod <- paste(c(fact, quad), collapse = "+")
lm2 <- lm(reformulate(termlabels = mod, response = "y"),
data = dat)
mm <- model.matrix(lm2)
mm <- mm[, 2:ncol(mm)]
trm <- firstm(y, mm)
d1 <- data.frame(y = y, mm[, trm])
t1 <- substr(trm, 1, 1)
t2 <- substr(trm, 2, 2)
t3 <- substr(trm, 3, 3)
iquad = FALSE
if (t1 == "I" & t2 == "(") {
iquad = TRUE
}
hmt <- trm
if (t2 == "") {
nms <- names(d1)
nms[2] <- hmt
names(d1) <- nms
}
m1 <- lm(y ~ (.), data = d1)
result <- summary(m1)
print(result)
return(trm)
}
<bytecode: 0x088fe000>
<environment: namespace:daewr>
--- function search by body ---
Function ihstep in namespace daewr has this body.
----------- END OF FAILURE REPORT --------------
Fatal error: the condition has length > 1
The problem is that the condition t1 == "I" & t2 == "(" of the if
statement in the code is not a scalar. Even though this has been allowed
in R historically, the first element has been used, it is almost always
a sign of coding error, so it is going to become a runtime error.
So what one should do is fix the code to only use scalar conditions -
ensure t1, t2 are scalar, replace & by &&.
You can enable these checks on your end using an environment variable
(more details are in R Internals, _R_CHECK_LENGTH_1_CONDITION_ and
related is _R_CHECK_LENGTH_1_LOGIC2_).|||
|
Best
Tomas
However on my own computer or on Rforge
I see this:
* checking examples ... OK
* DONE
Status: OK
-- R CMD check results ---------------------------------------- daewr 1.1-9 ----
Duration: 1m 1.8s
0 errors v | 0 warnings v | 0 notes v
R CMD check succeeded
I am not sure what the error is or how to correct it. Any help would
be greatly appreciated,
John Lawson
[[alternative HTML version deleted]]
The problem is that the condition t1 == "I" & t2 == "(" of the if
statement in the code is not a scalar. Even though this has been allowed
in R historically, the first element has been used, it is almost always
a sign of coding error, so it is going to become a runtime error.
So what one should do is fix the code to only use scalar conditions -
ensure t1, t2 are scalar, replace & by &&.
Perhaps I'm being even thicker than usual (imagine that!) but I don't
grok that last recommendation: "replace & by &&". It's usually
harmless but indicates a lack of understanding. The "&&" operator
evaluates the second condition only if the first condition is TRUE. It
is useful (only) in setting where the second condition is meaningful
only when the first condition is TRUE.
Things like:
if(!is.null(x) && x > 0)
If "x" were null then the second condition would cause an error to be
thrown if you used "&" rather than "&&".
In all (???) situations where "&&" works, then "&" works as well.
However it's a Good Idea to use the language as intended.
It I'm missing some point here, please enlighten me.
<SNIP>
cheers,
Rolf
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
It's not about god imposing style:). Consider this variant of your example:
flag <- !is.null(x) && x > 0
With the strict checking this will throw error when you run it (good). If you replace && with & and x is a vector, flag will silently become a vector and the error be masked or delayed and pop up far away.
Georgi Boshnakov
-----Original Message-----
From: R-package-devel <r-package-devel-bounces at r-project.org> On Behalf Of Rolf Turner
Sent: 05 March 2020 08:46
To: Tomas Kalibera <tomas.kalibera at gmail.com>
Cc: r-package-devel at r-project.org
Subject: Re: [R-pkg-devel] [FORGED] Re: Help on Windows CRAN Check
On 5/03/20 9:04 pm, Tomas Kalibera wrote:
On 3/5/20 4:26 AM, John Lawson wrote:
I see this error on the CRAN Check report
<SNIP>
Fatal error: the condition has length > 1
The problem is that the condition t1 == "I" & t2 == "(" of the if
statement in the code is not a scalar. Even though this has been
allowed in R historically, the first element has been used, it is
almost always a sign of coding error, so it is going to become a runtime error.
So what one should do is fix the code to only use scalar conditions -
ensure t1, t2 are scalar, replace & by &&.
Perhaps I'm being even thicker than usual (imagine that!) but I don't grok that last recommendation: "replace & by &&". It's usually harmless but indicates a lack of understanding. The "&&" operator evaluates the second condition only if the first condition is TRUE. It is useful (only) in setting where the second condition is meaningful only when the first condition is TRUE.
Things like:
if(!is.null(x) && x > 0)
If "x" were null then the second condition would cause an error to be thrown if you used "&" rather than "&&".
In all (???) situations where "&&" works, then "&" works as well.
However it's a Good Idea to use the language as intended.
It I'm missing some point here, please enlighten me.
<SNIP>
cheers,
Rolf
--
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
______________________________________________
R-package-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel
The problem is that the condition t1 == "I" & t2 == "(" of the if
statement in the code is not a scalar. Even though this has been allowed
in R historically, the first element has been used, it is almost always
a sign of coding error, so it is going to become a runtime error.
So what one should do is fix the code to only use scalar conditions -
ensure t1, t2 are scalar, replace & by &&.
Perhaps I'm being even thicker than usual (imagine that!) but I don't
grok that last recommendation:? "replace & by &&".? It's usually
harmless but indicates a lack of understanding.? The "&&" operator
evaluates the second condition only if the first condition is TRUE.?
It is useful (only) in setting where the second condition is
meaningful only when the first condition is TRUE.
Things like:
?? if(!is.null(x) && x > 0)
If "x" were null then the second? condition would cause an error to be
thrown if you used "&" rather than "&&".
In all (???) situations where "&&" works, then "&" works as well.
However it's a Good Idea to use the language as intended.
&& has short-circuit evaluation but also is intended for scalars. This
is reflected by that non-scalar arguments lead to a runtime error with
_R_CHECK_LENGTH_1_LOGIC2_=TRUE.
I use && in the code to indicate that I expect a scalar, and I want the
short-circuit evaluation for scalars as I am used to if from other
programming languages. I only use & when want element-wise operation on
vectors, when & is for computation (e.g. of indices).
Best
Tomas
It I'm missing some point here, please enlighten me.
<SNIP>
cheers,
Rolf
The problem is that the condition t1 == "I" & t2 == "(" of the if
statement in the code is not a scalar. Even though this has been allowed
in R historically, the first element has been used, it is almost always
a sign of coding error, so it is going to become a runtime error.
So what one should do is fix the code to only use scalar conditions -
ensure t1, t2 are scalar, replace & by &&.
Perhaps I'm being even thicker than usual (imagine that!)
Oh dear, but this time it is true...:
but I don't
grok that last recommendation:? "replace & by &&".? It's usually
harmless but indicates a lack of understanding.? The "&&" operator
evaluates the second condition only if the first condition is TRUE.? It
Right, and as the conditions are scalar, we never have to evaluate the
2nd if the first is FALSE unless you do it for side effects.
So for logical operators on scalar logical vectors, one should prefer &&
and || for efficeincy reasons.
Best,
Uwe
is useful (only) in setting where the second condition is meaningful
only when the first condition is TRUE.
Things like:
?? if(!is.null(x) && x > 0)
If "x" were null then the second? condition would cause an error to be
thrown if you used "&" rather than "&&".
In all (???) situations where "&&" works, then "&" works as well.
However it's a Good Idea to use the language as intended.
It I'm missing some point here, please enlighten me.
<SNIP>
cheers,
Rolf
This is something that, by the way, I've always thought R got backwards. If
you want an operation to handle "one thing" against "one other thing"
(scalars), a single & or | seems like the obvious symbol for it. Whereas an
operation on "multiple things" (vectors) would be well-represented by a
multiple-character symbol like && or ||.
But as long as I remember that it's backwards, I can keep them sorted out.
:-)
- Jeff
On Thu, Mar 5, 2020 at 6:14 AM Uwe Ligges <ligges at statistik.tu-dortmund.de>
wrote:
On 05.03.2020 09:45, Rolf Turner wrote:
On 5/03/20 9:04 pm, Tomas Kalibera wrote:
On 3/5/20 4:26 AM, John Lawson wrote:
I see this error on the CRAN Check report
<SNIP>
Fatal error: the condition has length > 1
The problem is that the condition t1 == "I" & t2 == "(" of the if
statement in the code is not a scalar. Even though this has been allowed
in R historically, the first element has been used, it is almost always
a sign of coding error, so it is going to become a runtime error.
So what one should do is fix the code to only use scalar conditions -
ensure t1, t2 are scalar, replace & by &&.
Perhaps I'm being even thicker than usual (imagine that!)
Oh dear, but this time it is true...:
but I don't
grok that last recommendation: "replace & by &&". It's usually
harmless but indicates a lack of understanding. The "&&" operator
evaluates the second condition only if the first condition is TRUE. It
Right, and as the conditions are scalar, we never have to evaluate the
2nd if the first is FALSE unless you do it for side effects.
So for logical operators on scalar logical vectors, one should prefer &&
and || for efficeincy reasons.
Best,
Uwe
is useful (only) in setting where the second condition is meaningful
only when the first condition is TRUE.
Things like:
if(!is.null(x) && x > 0)
If "x" were null then the second condition would cause an error to be
thrown if you used "&" rather than "&&".
In all (???) situations where "&&" works, then "&" works as well.
However it's a Good Idea to use the language as intended.
It I'm missing some point here, please enlighten me.
<SNIP>
cheers,
Rolf
Well, it originates in C, where & and | are bitwise operators.
-pd
On 5 Mar 2020, at 15:44 , Jeff Jetton <jeff.jetton at gmail.com> wrote:
This is something that, by the way, I've always thought R got backwards. If
you want an operation to handle "one thing" against "one other thing"
(scalars), a single & or | seems like the obvious symbol for it. Whereas an
operation on "multiple things" (vectors) would be well-represented by a
multiple-character symbol like && or ||.
But as long as I remember that it's backwards, I can keep them sorted out.
:-)
- Jeff
On Thu, Mar 5, 2020 at 6:14 AM Uwe Ligges <ligges at statistik.tu-dortmund.de>
wrote:
On 05.03.2020 09:45, Rolf Turner wrote:
On 5/03/20 9:04 pm, Tomas Kalibera wrote:
On 3/5/20 4:26 AM, John Lawson wrote:
I see this error on the CRAN Check report
<SNIP>
Fatal error: the condition has length > 1
The problem is that the condition t1 == "I" & t2 == "(" of the if
statement in the code is not a scalar. Even though this has been allowed
in R historically, the first element has been used, it is almost always
a sign of coding error, so it is going to become a runtime error.
So what one should do is fix the code to only use scalar conditions -
ensure t1, t2 are scalar, replace & by &&.
Perhaps I'm being even thicker than usual (imagine that!)
Oh dear, but this time it is true...:
but I don't
grok that last recommendation: "replace & by &&". It's usually
harmless but indicates a lack of understanding. The "&&" operator
evaluates the second condition only if the first condition is TRUE. It
Right, and as the conditions are scalar, we never have to evaluate the
2nd if the first is FALSE unless you do it for side effects.
So for logical operators on scalar logical vectors, one should prefer &&
and || for efficeincy reasons.
Best,
Uwe
is useful (only) in setting where the second condition is meaningful
only when the first condition is TRUE.
Things like:
if(!is.null(x) && x > 0)
If "x" were null then the second condition would cause an error to be
thrown if you used "&" rather than "&&".
In all (???) situations where "&&" works, then "&" works as well.
However it's a Good Idea to use the language as intended.
It I'm missing some point here, please enlighten me.
<SNIP>
cheers,
Rolf
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com