Skip to content

Commit c27b0aa

Browse files
Merge pull request #36 from m-muecke/paste-lint
refactor: use more expressive `paste0()` and `toString()` functions
2 parents 40f1d05 + fab2400 commit c27b0aa

6 files changed

Lines changed: 31 additions & 31 deletions

File tree

R/FDboost.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ FDboost <- function(formula, ### response ~ xvars
461461
equalBrackets <- NULL
462462
if(length(trmstrings) > 0){
463463
## insert id at end of each base-learner
464-
trmstrings2 <- paste(substr(trmstrings, 1 , nchar(trmstrings)-1), ", index=", id[2],")", sep = "")
464+
trmstrings2 <- paste0(substr(trmstrings, 1 , nchar(trmstrings)-1), ", index=", id[2],")")
465465
## check if number of opening brackets is equal to number of closing brackets
466466
equalBrackets <- sapply(seq_along(trmstrings2), function(i)
467467
{
@@ -493,7 +493,7 @@ FDboost <- function(formula, ### response ~ xvars
493493
## delete all trailing whitespace
494494
trim.trailing <- function (x) sub("\\s+$", "", x)
495495
temp1 <- trim.trailing(temp1)
496-
temp1 <- paste(substr(temp1, 1 , nchar(temp1)-1), ", index=", id[2],")", sep = "")
496+
temp1 <- paste0(substr(temp1, 1 , nchar(temp1)-1), ", index=", id[2],")")
497497
trmstrings2[i] <- paste0(paste0(temp1, collapse = " %X"), " %X", temp[length(temp)])
498498
}
499499
## do not add index to base-learners bhistx()
@@ -714,10 +714,10 @@ FDboost <- function(formula, ### response ~ xvars
714714
# set c_df to the df/lambda in timeformula
715715
if( grepl("lambda", tfm) ||
716716
( grepl("bols", tfm) && !grepl("df", tfm)) ){
717-
c_lambda <- eval(parse(text = paste(tfm, "$dpp(rep(1.0,", length(time), "))$df()", sep = "")))["lambda"]
717+
c_lambda <- eval(parse(text = paste0(tfm, "$dpp(rep(1.0,", length(time), "))$df()")))["lambda"]
718718
cfm <- paste("bols(ONEtime, intercept = FALSE, lambda = ", c_lambda ,")")
719719
} else{
720-
c_df <- eval(parse(text=paste(tfm, "$dpp(rep(1.0,", length(time), "))$df()", sep = "")))["df"]
720+
c_df <- eval(parse(text=paste0(tfm, "$dpp(rep(1.0,", length(time), "))$df()")))["df"]
721721
cfm <- paste("bols(ONEtime, intercept = FALSE, df = ", c_df ,")")
722722
}
723723
}
@@ -737,8 +737,8 @@ FDboost <- function(formula, ### response ~ xvars
737737
} else{
738738
which_equalBrackets <- which(equalBrackets)
739739
}
740-
xfmTemp <- paste(substr(xfm[which_equalBrackets], 1 ,
741-
nchar(xfm[which_equalBrackets]) - 1 ), ")", sep = "") # , index=id is done in the beginning
740+
xfmTemp <- paste0(substr(xfm[which_equalBrackets], 1 ,
741+
nchar(xfm[which_equalBrackets]) - 1 ), ")") # , index=id is done in the beginning
742742
xfm[which_equalBrackets] <- xfmTemp
743743
rm(xfmTemp)
744744
tmp <- outer(xfm, tfm, function(x, y) paste(x, y, sep = "%X%"))

R/baselearners.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ X_bsignal <- function(mf, vary, args) {
273273
"linear" = matrix(c(rep(1, length(xind)), xind), ncol=2),
274274
"constant"= matrix(c(rep(1, length(xind))), ncol=1))
275275

276-
colnames(Bs) <- paste(xname, seq_len(ncol(Bs)), sep="")
276+
colnames(Bs) <- paste0(xname, seq_len(ncol(Bs)))
277277

278278

279279
# use cyclic splines
@@ -288,7 +288,7 @@ X_bsignal <- function(mf, vary, args) {
288288
fun = "cbs")
289289
}
290290

291-
colnames(Bs) <- paste(xname, seq_len(ncol(Bs)), sep="")
291+
colnames(Bs) <- paste0(xname, seq_len(ncol(Bs)))
292292

293293
### Penalty matrix: product differences matrix
294294
if (args$differences > 0){
@@ -701,7 +701,7 @@ bsignal <- function(x, s, index = NULL, inS = c("smooth", "linear", "constant"),
701701

702702
if(is.null(Z) &&
703703
all( abs(rowMeans(x, na.rm = TRUE)-mean(rowMeans(x, na.rm = TRUE))) < .Machine$double.eps *10^10)){
704-
message(paste("All trajectories in ", xname, " have the same mean. Coefficient function is centered.", sep=""))
704+
message(paste0("All trajectories in ", xname, " have the same mean. Coefficient function is centered."))
705705
}
706706

707707
# mf <- mfL
@@ -870,7 +870,7 @@ X_conc <- function(mf, vary, args) {
870870
fun = "cbs")
871871
}
872872

873-
colnames(Bs) <- paste(xname, seq_len(ncol(Bs)), sep="")
873+
colnames(Bs) <- paste0(xname, seq_len(ncol(Bs)))
874874

875875
# set up design matrix for concurrent model
876876
if(args$format=="wide"){
@@ -1176,7 +1176,7 @@ X_hist <- function(mf, vary, args) {
11761176
"linear" = matrix(c(rep(1, length(xind)), xind), ncol = 2),
11771177
"constant"= matrix(c(rep(1, length(xind))), ncol = 1))
11781178

1179-
colnames(Bs) <- paste(xname, seq_len(ncol(Bs)), sep="")
1179+
colnames(Bs) <- paste0(xname, seq_len(ncol(Bs)))
11801180

11811181
# integration weights
11821182
L <- args$intFun(X1=X1, xind=xind)
@@ -1700,7 +1700,7 @@ X_fpc <- function(mf, vary, args) {
17001700

17011701
}
17021702

1703-
colnames(X) <- paste(xname, ".PC", seq_len(ncol(X)), sep = "")
1703+
colnames(X) <- paste0(xname, ".PC", seq_len(ncol(X)))
17041704

17051705
## set up the penalty matrix
17061706
K <- switch(args$penalty,
@@ -2337,8 +2337,8 @@ X_olsc <- function(mf, vary, args) {
23372337
contr <- NULL
23382338
} else {
23392339
### set up model matrix
2340-
fm <- paste("~ ", paste(colnames(mf)[colnames(mf) != vary],
2341-
collapse = "+"), sep = "")
2340+
fm <- paste0("~ ", paste(colnames(mf)[colnames(mf) != vary],
2341+
collapse = "+"))
23422342
fac <- sapply(mf[colnames(mf) != vary], is.factor)
23432343
DUMMY <- FALSE
23442344
if (any(fac)){

R/baselearnersX.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ X_histx <- function(mf, vary, args) {
9292
"linear" = matrix(c(rep(1, length(xind)), xind), ncol = 2),
9393
"constant"= matrix(c(rep(1, length(xind))), ncol = 1))
9494

95-
colnames(Bs) <- paste(xname, seq_len(ncol(Bs)), sep="")
95+
colnames(Bs) <- paste0(xname, seq_len(ncol(Bs)))
9696

9797
# integration weights
9898
L <- args$intFun(X1=X1, xind=xind)

R/crossvalidation.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ applyFolds <- function(object, folds = cv(rep(1, length(unique(object$id))), typ
305305

306306
if(any(!grepl("\\(", singleBls)))
307307
stop(paste0("applyFolds can not deal with the following base-learner(s) without brackets: ",
308-
paste(singleBls[!grepl("\\(", singleBls)], collapse = ", ")))
308+
toString(singleBls[!grepl("\\(", singleBls)])))
309309

310310

311311
## check if data includes all variables
@@ -321,7 +321,7 @@ applyFolds <- function(object, folds = cv(rep(1, length(unique(object$id))), typ
321321
any( grepl(w, object$baselearner[[i]]$get_names() ) )) return(i))
322322
)[1])
323323

324-
stop(paste0("base-learner(s) ", paste(unlist(list(1,2)), collapse = ", "),
324+
stop(paste0("base-learner(s) ", toString(unlist(list(1,2))),
325325
" contain(s) variables, which are not part of the data object."))
326326

327327
}
@@ -914,7 +914,7 @@ validateFDboost <- function(object, response = NULL,
914914
# stop() or warning()?
915915
if(sum(!modFitted) > sum(modFitted)) warning("More than half of the models could not be fitted.")
916916

917-
warning("Model fit did not work in fold ", paste(which(!modFitted), collapse = ", "))
917+
warning("Model fit did not work in fold ", toString(which(!modFitted)))
918918
modRisk <- modRisk[modFitted]
919919
OOBweights <- OOBweights[,modFitted]
920920
folds <- folds[,modFitted]
@@ -1585,7 +1585,7 @@ plot_bootstrapped_coef <- function(temp, l,
15851585
xlab=paste("\n", temp$xlab), ylab=paste("\n", temp$ylab),
15861586
zlab=paste("\n", "coef"),
15871587
zlim=if(any(is.null(ylim))) range(matvec, na.rm=TRUE) else ylim,
1588-
main=paste(temp$main, " at ", probs[k]*100, "%-quantile", sep=""),
1588+
main=paste0(temp$main, " at ", probs[k]*100, "%-quantile"),
15891589
col=getColPersp(tempZ)))
15901590

15911591
}
@@ -1620,7 +1620,7 @@ plot_bootstrapped_coef <- function(temp, l,
16201620
myargs=list(x=temp$y, y=temp$x, z=t(tempZ), xlab=paste("\n", temp$xlab),
16211621
ylab=paste("\n", temp$ylab), zlim=c(min(matvec, na.rm=TRUE),
16221622
max(matvec, na.rm=TRUE)),
1623-
main=paste(temp$main, " at ", probs[k]*100, "%-quantile", sep=""),
1623+
main=paste0(temp$main, " at ", probs[k]*100, "%-quantile"),
16241624
col = heat.colors(length(temp$x)^2)
16251625
)
16261626
)
@@ -1643,16 +1643,16 @@ plot_bootstrapped_coef <- function(temp, l,
16431643
myRow <- t(temp$value[[which(quantx[j]==temp$x)]])
16441644

16451645
plot_curves(x_i = temp$y, y_i = myRow, xlab_i = temp$ylab,
1646-
main_i = paste(temp$main, " at ", temp$xlab,"=" ,quantx[j], sep = ""),
1646+
main_i = paste0(temp$main, " at ", temp$xlab,"=" ,quantx[j]),
16471647
ylim_i = ylim)
16481648

16491649
}else{
16501650
quantz <- temp$z
16511651
myRow <- sapply(temp$value, function(x) x[quantx[j]==temp$x & quantz[j]==temp$z, ]) # first column
16521652

16531653
plot_curves(x_i = temp$y, y_i = myRow, xlab_i = temp$ylab,
1654-
main_i = paste(temp$main, " at ", temp$xlab, "=" , quantx[j], ", " ,
1655-
temp$zlab, "=", quantz[j], sep = ""),
1654+
main_i = paste0(temp$main, " at ", temp$xlab, "=" , quantx[j], ", " ,
1655+
temp$zlab, "=", quantz[j]),
16561656
ylim_i = ylim)
16571657
}
16581658
}
@@ -1713,7 +1713,7 @@ cvLong <- function(id, weights = rep(1, l=length(id)),
17131713
B = B, prob = prob, strata = strata)
17141714
foldsLong <- folds[id, , drop = FALSE] * weights
17151715
}
1716-
attr(foldsLong, "type") <- paste(B, "-fold ", type, sep = "")
1716+
attr(foldsLong, "type") <- paste0(B, "-fold ", type)
17171717
return(foldsLong)
17181718

17191719
}

R/methods.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,12 +1258,12 @@ coef.FDboost <- function(object, raw = FALSE, which = NULL,
12581258
temp[1] <- unlist(strsplit(temp[1], "(", fixed=TRUE))[1]
12591259
if(substr(temp[2], 1, 1)==" ") temp[2] <- substr(temp[2], 2, nchar(temp[2]))
12601260
if(length(commaSep) == 1){
1261-
xpart[i] <- paste(temp[1], "(", temp[2], sep="")
1261+
xpart[i] <- paste0(temp[1], "(", temp[2])
12621262
}else{
1263-
xpart[i] <- paste(temp[1], "(", temp[2], ")", sep="")
1263+
xpart[i] <- paste0(temp[1], "(", temp[2], ")")
12641264
}
12651265
}else{
1266-
if(length(commaSep) > 1){ xpart[i] <- paste(commaSep[1], ")", sep="")}
1266+
if(length(commaSep) > 1){ xpart[i] <- paste0(commaSep[1], ")")}
12671267
}
12681268
#xpart[i] <- if(length(commaSep)==1){
12691269
# paste(paste(commaSep[1:nvar], collapse=","), sep="")
@@ -1641,7 +1641,7 @@ plot.FDboost <- function(x, raw = FALSE, rug = TRUE, which = NULL,
16411641
ylab=paste("\n", trm$ylab), zlab=paste("\n", "coef"),
16421642
theta=30, phi=30, ticktype="detailed",
16431643
zlim=range(trm$value), col=getColPersp(trm$value[[j]]),
1644-
main= paste(trm$zlab ,"=", round(trm$z[j],2), ": ", trm$main, sep=""))
1644+
main= paste0(trm$zlab ,"=", round(trm$z[j],2), ": ", trm$main))
16451645
)
16461646
}
16471647
}
@@ -1651,7 +1651,7 @@ plot.FDboost <- function(x, raw = FALSE, rug = TRUE, which = NULL,
16511651
plotWithArgs(image, args=argsImage,
16521652
myargs=list(x=trm$x, y=trm$y, z=trm$value[[j]], xlab=trm$xlab, ylab=trm$ylab,
16531653
col = heat.colors(length(trm$x)^2), zlim=range(trm$value),
1654-
main= paste(trm$zlab ,"=", round(trm$z[j],2), ": ", trm$main, sep="")))
1654+
main= paste0(trm$zlab ,"=", round(trm$z[j],2), ": ", trm$main)))
16551655
plotWithArgs(contour, args=argsContour,
16561656
myargs=list(trm$x, trm$y, trm$value[[j]], xlab=trm$xlab, add = TRUE))
16571657
if(rug){
@@ -1889,7 +1889,7 @@ update.FDboost <- function(object, weights = NULL, oobweights = NULL, risk = NUL
18891889

18901890
if(any( !grepl("\\(",singleBls) ))
18911891
stop(paste0("update can not deal with the following base-learner(s) without brackets: ",
1892-
paste(singleBls[!grepl("\\(",singleBls)], collapse=", "), ".\n",
1892+
toString(singleBls[!grepl("\\(",singleBls)]), ".\n",
18931893
"Please build such base-learners within the FDboost call or ",
18941894
"update corresponding baselearner(s) manually and supply a new formula to the update function."))
18951895

R/utilityFunctions.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ reweightData <- function(data, argvals, vars,
10451045
# check names
10461046
if(length(whichNot) != 0)
10471047
stop(paste0("Could not find ",
1048-
paste(c(argvals, vars, idvars, longvars)[whichNot], collapse = ", "),
1048+
toString(c(argvals, vars, idvars, longvars)[whichNot]),
10491049
" in data."))
10501050

10511051
# check for hmatrix and delete in argvals or vars if present

0 commit comments

Comments
 (0)