Skip to content

Commit 22c3a68

Browse files
Merge pull request #40 from m-muecke/lengths
perf: use `lengths()` instead of `sapply(x, length)`
2 parents 31827c2 + e5ff0f8 commit 22c3a68

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

R/FDboost.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,8 @@ FDboost <- function(formula, ### response ~ xvars
465465
## check if number of opening brackets is equal to number of closing brackets
466466
equalBrackets <- sapply(seq_along(trmstrings2), function(i)
467467
{
468-
sapply(regmatches(trmstrings2[i], gregexpr("\\(", trmstrings2[i])), length) ==
469-
sapply(regmatches(trmstrings2[i], gregexpr("\\)", trmstrings2[i])), length)
468+
lengths(regmatches(trmstrings2[i], gregexpr("\\(", trmstrings2[i]))) ==
469+
lengths(regmatches(trmstrings2[i], gregexpr("\\)", trmstrings2[i])))
470470
})
471471
}
472472

@@ -621,7 +621,7 @@ FDboost <- function(formula, ### response ~ xvars
621621
nr <- nrow(response)
622622
if(!is.list(time))
623623
stopifnot(ncol(response) == length(time)) else
624-
stopifnot(all(ncol(response) == sapply(time[sapply(time, is.vector)], length)))
624+
stopifnot(all(ncol(response) == lengths(time[sapply(time, is.vector)])))
625625
nc <- ncol(response)
626626
dresponse <- as.vector(response) # column-wise stacking of response
627627
## convert characters to factor
@@ -633,7 +633,7 @@ FDboost <- function(formula, ### response ~ xvars
633633
stopifnot(is.null(dim(response))) ## stopifnot(is.vector(response))
634634
# check length of response and its time and index
635635
if(is.list(time))
636-
stopifnot(all(length(response) == sapply(time, length)) & length(response) == length(id)) else
636+
stopifnot(all(length(response) == lengths(time)) & length(response) == length(id)) else
637637
stopifnot(length(response) == length(time) & length(response) == length(id))
638638

639639
if(anyNA(response)) warning("For non-grid observations the response should not contain missing values.")
@@ -944,7 +944,7 @@ FDboost <- function(formula, ### response ~ xvars
944944
### multiply integration weights numInt to weights and w
945945
if(is.numeric(numInt)){
946946
.numInt_len_check <- if(is.list(time))
947-
all(length(numInt) == sapply(time, length)) else
947+
all(length(numInt) == lengths(time)) else
948948
length(numInt) == length(time)
949949
if(!.numInt_len_check)
950950
stop("Length of integration weights and time vector are not equal.")

0 commit comments

Comments
 (0)