Skip to content

Commit 02ee30e

Browse files
committed
refactor: enforce && and || in conditional expressions
1 parent c57e67a commit 02ee30e

8 files changed

Lines changed: 94 additions & 94 deletions

File tree

R/FDboost.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ FDboost <- function(formula, ### response ~ xvars
538538
scalarResponse <- TRUE
539539
if(is.null(timeformula)) scalarNoFLAM <- TRUE
540540

541-
if(grepl("df", formula[3]) | !grepl("lambda", formula[3]) ){
541+
if(grepl("df", formula[3]) || !grepl("lambda", formula[3]) ){
542542
timeformula <- ~bols(ONEtime, intercept = FALSE, df = 1)
543543
}else{
544544
timeformula <- ~bols(ONEtime, intercept = FALSE)
@@ -555,7 +555,7 @@ FDboost <- function(formula, ### response ~ xvars
555555

556556
}
557557

558-
if(scalarResponse & !identical(numInt,"equal"))
558+
if(scalarResponse && !identical(numInt,"equal"))
559559
stop("Integration weights numInt must be set to 'equal' for scalar response.")
560560

561561
## extract time(s) from timeformula
@@ -713,7 +713,7 @@ FDboost <- function(formula, ### response ~ xvars
713713
if(length(where.c) > 0){
714714
# set c_df to the df/lambda in timeformula
715715
if( grepl("lambda", tfm) ||
716-
( grepl("bols", tfm) & !grepl("df", tfm)) ){
716+
( grepl("bols", tfm) && !grepl("df", tfm)) ){
717717
c_lambda <- eval(parse(text = paste(tfm, "$dpp(rep(1.0,", length(time), "))$df()", sep = "")))["lambda"]
718718
cfm <- paste("bols(ONEtime, intercept = FALSE, lambda = ", c_lambda ,")")
719719
} else{
@@ -973,7 +973,7 @@ FDboost <- function(formula, ### response ~ xvars
973973
### -> use one scalar/user-specified offset like in mboost
974974

975975
### in case of factor or multiple time variables set offset to 0 and give a warning
976-
if(is.list(time) | !is.numeric(time)) {
976+
if(is.list(time) || !is.numeric(time)) {
977977
.offsetwarning <- is.null(offset)
978978
if(!.offsetwarning) {
979979
.offsetwarning <- (offset == "scalar")
@@ -1081,7 +1081,7 @@ FDboost <- function(formula, ### response ~ xvars
10811081
offset <- as.vector(matrix(offsetVec, ncol = ncol(response), nrow = nrow(response), byrow = TRUE))
10821082
}else{
10831083
### scalar response or mean-centered response -> one constant offset value is used
1084-
if(dim(response)[2] == 1 | all(colMeans(response, na.rm = TRUE) < .Machine$double.eps *10^10)){
1084+
if(dim(response)[2] == 1 || all(colMeans(response, na.rm = TRUE) < .Machine$double.eps *10^10)){
10851085
offsetVec <- offset
10861086
predictOffset <- offset
10871087
}else{

R/baselearners.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ hyper_signal <- function(mf, vary, inS="smooth", knots = 10, boundary.knots = NU
236236

237237
ret <- knotf(s, knots, boundary.knots)
238238

239-
if (cyclic & constraint != "none")
239+
if (cyclic && constraint != "none")
240240
stop("constraints not implemented for cyclic B-splines")
241241
stopifnot(is.numeric(deriv) & length(deriv) == 1)
242242

@@ -1116,7 +1116,7 @@ hyper_hist <- function(mf, vary, knots = 10, boundary.knots = NULL, degree = 3,
11161116
boundary.knots[[n]]
11171117
else boundary.knots)
11181118

1119-
if (cyclic & constraint != "none")
1119+
if (cyclic && constraint != "none")
11201120
stop("constraints not implemented for cyclic B-splines")
11211121
stopifnot(is.numeric(deriv) & length(deriv) == 1)
11221122

@@ -1474,7 +1474,7 @@ bhist <- function(x, s, time, index = NULL, #by = NULL,
14741474
# compare range of index signal and index response
14751475
# minimal value of the signal-index has to be smaller than the response-index
14761476
if(!is.function(limits)){
1477-
if(limits=="s<=t" & min(s) > min(time) ) stop("Index of response has values before index of signal.")
1477+
if(limits=="s<=t" && min(s) > min(time) ) stop("Index of response has values before index of signal.")
14781478
}
14791479

14801480
# Reshape mfL so that it is the dataframe of the signal with

R/baselearnersX.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ hyper_histx <- function(mf, vary, knots = 10, boundary.knots = NULL, degree = 3,
4040
ret[[n]] <- knotf(getTime(mf[[n]]),
4141
knots=if(is.list(knots)) knots[[n]] else knots,
4242
boundary.knots = if(is.list(boundary.knots)) boundary.knots[[n]] else boundary.knots)
43-
if (cyclic & constraint != "none")
43+
if (cyclic && constraint != "none")
4444
stop("constraints not implemented for cyclic B-splines")
4545
stopifnot(is.numeric(deriv) & length(deriv) == 1)
4646

R/bootstrapCIs.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ bootstrapCI <- function(object, which = NULL,
227227
}
228228

229229
# 'catch' error caused by using the cvrisk function for inner and outer resampling
230-
if(identical(resampling_fun_outer, cvrisk) &
230+
if(identical(resampling_fun_outer, cvrisk) &&
231231
identical(resampling_fun_inner, cvrisk))
232232
stop("Please specify a different outer resampling function.")
233233

@@ -312,18 +312,18 @@ bootstrapCI <- function(object, which = NULL,
312312
}
313313

314314
aty <- NA
315-
if(isSurface[i] | isFacEffect[i]) aty <- coefs[[1]]$smterms[[i]]$y
315+
if(isSurface[i] || isFacEffect[i]) aty <- coefs[[1]]$smterms[[i]]$y
316316
if(isFacSpecEffect[i]) aty <- coefs[[1]]$smterms[[i]][[1]]$y
317317

318318
# format functional factors
319-
if(is.list(listOfCoefs[[i]]) & is.factor(atx)){
319+
if(is.list(listOfCoefs[[i]]) && is.factor(atx)){
320320

321321
# combine each factor level
322322
listOfCoefs[[i]] <- lapply(seq_along(levels(droplevels(atx))),
323323
function(faclevnr) t(sapply(listOfCoefs[[i]], function(x) x[faclevnr,])))
324324
isSurface[i] <- FALSE
325325

326-
}else if(is.list(listOfCoefs[[i]]) & !isFacSpecEffect[i]){ # effect surfaces
326+
}else if(is.list(listOfCoefs[[i]]) && !isFacSpecEffect[i]){ # effect surfaces
327327

328328
listOfCoefs[[i]] <- do.call("rbind", lapply(listOfCoefs[[i]],c))
329329

@@ -378,7 +378,7 @@ bootstrapCI <- function(object, which = NULL,
378378
for(i in seq_along(listOfCoefs)){
379379

380380
# for matrix object
381-
if(is.matrix(listOfCoefs[[i]]) & !is.list(listOfCoefs[[i]])){
381+
if(is.matrix(listOfCoefs[[i]]) && !is.list(listOfCoefs[[i]])){
382382

383383
listOfQuantiles[[i]] <- apply(listOfCoefs[[i]], 2, quantile, probs = levels)
384384
attr(listOfQuantiles[[i]], "x") <- attr(listOfCoefs[[i]], "x")
@@ -520,7 +520,7 @@ plot.bootstrapCI <- function(x, which = NULL, pers = TRUE,
520520
if(length(which)>1) par(ask=ask)
521521

522522
# find common range for all effects
523-
if(commonRange & is.null(ylim)){
523+
if(commonRange && is.null(ylim)){
524524
ylim <- range(x$raw_results)
525525
if(any(is.infinite(ylim))) ylim <- NULL
526526
}
@@ -548,7 +548,7 @@ plot.bootstrapCI <- function(x, which = NULL, pers = TRUE,
548548
}else{
549549
## temp$dim == 1 like in scalar response with bsignal()
550550
## put each fold into one list entry
551-
if(length(x$yind) <= 1 & x$family != "Binomial Distribution (similar to glm)"){
551+
if(length(x$yind) <= 1 && x$family != "Binomial Distribution (similar to glm)"){
552552
# scalar response and not Binomial
553553
temp$value <- split(temp_CI, rep(1:x$B_outer, each = length(temp_CI)/x$B_outer))
554554
}else{
@@ -559,7 +559,7 @@ plot.bootstrapCI <- function(x, which = NULL, pers = TRUE,
559559

560560
}else{
561561

562-
if(is.null(temp$numberLevels) & is.factor(temp$x)){
562+
if(is.null(temp$numberLevels) && is.factor(temp$x)){
563563

564564
## for time-varying factor effects
565565
temp$value <- temp_CI
@@ -573,7 +573,7 @@ plot.bootstrapCI <- function(x, which = NULL, pers = TRUE,
573573
}
574574
}
575575

576-
if(!is.null(temp$dim) && temp$dim == 2 & !is.factor(temp$x)){
576+
if(!is.null(temp$dim) && temp$dim == 2 && !is.factor(temp$x)){
577577
temp$value <- lapply(temp$value, function(xx)
578578
matrix(xx, ncol = sqrt(length(xx)), nrow = sqrt(length(xx)), byrow = FALSE) )
579579
}

R/constrainedX.R

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
if(any(used_bl == "bolsc")) stop("Use bols instead of bolsc with %Xc%.")
9090
if(any(used_bl == "brandomc")) stop("Use brandom instead of brandomc with %Xc%.")
9191
if(any(used_bl == "bbsc")) stop("Use bbs instead of bbsc with %Xc%.")
92-
if( (!is.null(match.call()$bl1$intercept) && match.call()$bl1$intercept != TRUE) |
92+
if( (!is.null(match.call()$bl1$intercept) && match.call()$bl1$intercept != TRUE) ||
9393
(!is.null(match.call()$bl2$intercept) && match.call()$bl2$intercept != TRUE) ){
9494
stop("Set intercept = TRUE in base-learners used with %Xc%.")
9595
}
@@ -172,19 +172,19 @@
172172
X1 <- X1$X
173173
if (!is.null(l1)) K1 <- l1 * K1
174174
MATRIX <- options("mboost_useMatrix")$mboost_useMatrix
175-
if (MATRIX & !is(X1, "Matrix"))
175+
if (MATRIX && !is(X1, "Matrix"))
176176
X1 <- Matrix(X1)
177-
if (MATRIX & !is(K1, "Matrix"))
177+
if (MATRIX && !is(K1, "Matrix"))
178178
K1 <- Matrix(K1)
179179

180180
X2 <- newX2(mf[, bl2$get_names(), drop = FALSE],
181181
prediction = args$prediction)
182182
K2 <- X2$K
183183
X2 <- X2$X
184184
if (!is.null(l2)) K2 <- l2 * K2
185-
if (MATRIX & !is(X2, "Matrix"))
185+
if (MATRIX && !is(X2, "Matrix"))
186186
X2 <- Matrix(X2)
187-
if (MATRIX & !is(K2, "Matrix"))
187+
if (MATRIX && !is(K2, "Matrix"))
188188
K2 <- Matrix(K2)
189189
suppressMessages(
190190
X <- kronecker(X1, Matrix(1, ncol = ncol(X2),
@@ -344,7 +344,7 @@ bl_lin_matrix_a <- function(blg, Xfun, args) {
344344
if( all(abs(multFactor - multFactor[1] ) < .Machine$double.eps*10^10) ) multFactor <- multFactor[1]
345345

346346
## case that W and w1w2 just differ by a factor
347-
if( all((W == w1w2)[w1w2 == 0]) & all((W == w1w2)[W == 0]) & ## check positions of zeros
347+
if( all((W == w1w2)[w1w2 == 0]) && all((W == w1w2)[W == 0]) && ## check positions of zeros
348348
length(multFactor) == 1 ){ # check that only 1 multiplicative factor
349349

350350
## it is impossible to know whether multFactor is multiplied to w1 or w2!
@@ -783,19 +783,19 @@ NULL
783783
X1 <- X1$X
784784
if (!is.null(l1)) K1 <- l1 * K1
785785
MATRIX <- options("mboost_useMatrix")$mboost_useMatrix
786-
if (MATRIX & !is(X1, "Matrix"))
786+
if (MATRIX && !is(X1, "Matrix"))
787787
X1 <- Matrix(X1)
788-
if (MATRIX & !is(K1, "Matrix"))
788+
if (MATRIX && !is(K1, "Matrix"))
789789
K1 <- Matrix(K1)
790790

791791
X2 <- newX2(as.data.frame(mf[bl2$get_names()]),
792792
prediction = args$prediction)
793793
K2 <- X2$K
794794
X2 <- X2$X
795795
if (!is.null(l2)) K2 <- l2 * K2
796-
if (MATRIX & !is(X2, "Matrix"))
796+
if (MATRIX && !is(X2, "Matrix"))
797797
X2 <- Matrix(X2)
798-
if (MATRIX & !is(K2, "Matrix"))
798+
if (MATRIX && !is(K2, "Matrix"))
799799
K2 <- Matrix(K2)
800800
suppressMessages(
801801
K <- kronecker(K2, diag(ncol(X1))) +
@@ -912,7 +912,7 @@ NULL
912912
}
913913
}
914914

915-
if(args$lambda1 != 0 & args$lambda2 != 0)
915+
if(args$lambda1 != 0 && args$lambda2 != 0)
916916
stop("%A0% can only be used when smoothing parameter is zero for one direction.")
917917

918918
l1 <- args$lambda1
@@ -931,19 +931,19 @@ NULL
931931
X1 <- X1$X
932932
if (!is.null(l1)) K1 <- l1 * K1
933933
MATRIX <- options("mboost_useMatrix")$mboost_useMatrix
934-
if (MATRIX & !is(X1, "Matrix"))
934+
if (MATRIX && !is(X1, "Matrix"))
935935
X1 <- Matrix(X1)
936-
if (MATRIX & !is(K1, "Matrix"))
936+
if (MATRIX && !is(K1, "Matrix"))
937937
K1 <- Matrix(K1)
938938

939939
X2 <- newX2(as.data.frame(mf[bl2$get_names()]),
940940
prediction = args$prediction)
941941
K2 <- X2$K
942942
X2 <- X2$X
943943
if (!is.null(l2)) K2 <- l2 * K2
944-
if (MATRIX & !is(X2, "Matrix"))
944+
if (MATRIX && !is(X2, "Matrix"))
945945
X2 <- Matrix(X2)
946-
if (MATRIX & !is(K2, "Matrix"))
946+
if (MATRIX && !is(K2, "Matrix"))
947947
K2 <- Matrix(K2)
948948
suppressMessages(
949949
K <- kronecker(K2, diag(ncol(X1))) +
@@ -1075,7 +1075,7 @@ NULL
10751075
}
10761076
}
10771077

1078-
if(args$lambda1 != 0 & args$lambda2 != 0)
1078+
if(args$lambda1 != 0 && args$lambda2 != 0)
10791079
stop("%Xa0% can only be used when smoothing parameter is zero for one direction.")
10801080

10811081
l1 <- args$lambda1
@@ -1094,19 +1094,19 @@ NULL
10941094
X1 <- X1$X
10951095
if (!is.null(l1)) K1 <- l1 * K1
10961096
MATRIX <- options("mboost_useMatrix")$mboost_useMatrix
1097-
if (MATRIX & !is(X1, "Matrix"))
1097+
if (MATRIX && !is(X1, "Matrix"))
10981098
X1 <- Matrix(X1)
1099-
if (MATRIX & !is(K1, "Matrix"))
1099+
if (MATRIX && !is(K1, "Matrix"))
11001100
K1 <- Matrix(K1)
11011101

11021102
X2 <- newX2(mf[, bl2$get_names(), drop = FALSE],
11031103
prediction = args$prediction)
11041104
K2 <- X2$K
11051105
X2 <- X2$X
11061106
if (!is.null(l2)) K2 <- l2 * K2
1107-
if (MATRIX & !is(X2, "Matrix"))
1107+
if (MATRIX && !is(X2, "Matrix"))
11081108
X2 <- Matrix(X2)
1109-
if (MATRIX & !is(K2, "Matrix"))
1109+
if (MATRIX && !is(K2, "Matrix"))
11101110
K2 <- Matrix(K2)
11111111
suppressMessages(
11121112
X <- kronecker(X1, Matrix(1, ncol = ncol(X2),

R/crossvalidation.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ applyFolds <- function(object, folds = cv(rep(1, length(unique(object$id))), typ
255255
}
256256
}
257257

258-
if(!any(class(object) == "FDboostLong") & !any(class(object) == "FDboostScalar")){
258+
if(!any(class(object) == "FDboostLong") && !any(class(object) == "FDboostScalar")){
259259
dathelp[[object$yname]] <- matrix(object$response, ncol=object$ydim[2])
260260
dathelp$integration_weights <- matrix(integration_weights, ncol=object$ydim[2])
261261
dathelp$object_id <- object$id
@@ -783,7 +783,7 @@ validateFDboost <- function(object, response = NULL,
783783
nameyind <- attr(object$yind, "nameyind")
784784
dathelp[[nameyind]] <- object$yind
785785

786-
if(!any(class(object) == "FDboostLong") & !any(class(object) == "FDboostScalar")){
786+
if(!any(class(object) == "FDboostLong") && !any(class(object) == "FDboostScalar")){
787787
dathelp[[object$yname]] <- matrix(object$response, ncol = Gy)
788788
}else{
789789
dathelp[[object$yname]] <- object$response
@@ -1287,7 +1287,7 @@ plot.validateFDboost <- function(x, riskopt=c("mean", "median"),
12871287
}
12881288

12891289
# Plot the predictions for the optimal mstop
1290-
if(4 %in% which | 5 %in% which){
1290+
if(4 %in% which || 5 %in% which){
12911291

12921292
if(!is.null(x$oobpreds)){
12931293
response <- x$response
@@ -1376,7 +1376,7 @@ plotPredCoef <- function(x, which = NULL, pers = TRUE,
13761376
return(NULL)
13771377
}
13781378

1379-
if(commonRange & is.null(ylim)){
1379+
if(commonRange && is.null(ylim)){
13801380
ylim <- range(x$predCV[which])
13811381
}
13821382

@@ -1407,7 +1407,7 @@ plotPredCoef <- function(x, which = NULL, pers = TRUE,
14071407

14081408
}else{ # plot coefficients
14091409

1410-
if(commonRange & is.null(ylim)){
1410+
if(commonRange && is.null(ylim)){
14111411
if(length(x$yind)>1){
14121412
if(!any(sapply(lapply(x$coefCV[which], function(x) x$value), is.null))){
14131413
ylim <- range(lapply(x$coefCV[which], function(x) x$value))

0 commit comments

Comments
 (0)