Skip to content

Commit eea49dc

Browse files
Merge pull request #944 from tidymodels/no-colon
don't use colon programatically
2 parents e7f7b41 + b0e1a9f commit eea49dc

File tree

7 files changed

+9
-13
lines changed

7 files changed

+9
-13
lines changed

R/adds.R

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ add_rowindex <- function(x) {
99
if (!is.data.frame(x)) {
1010
rlang::abort("`x` should be a data frame.")
1111
}
12-
if (nrow(x) > 0) {
13-
x <- dplyr::mutate(x, .row = 1:nrow(x))
14-
} else {
15-
x$.row <- integer(0)
16-
}
12+
x <- dplyr::mutate(x, .row = seq_len(nrow(x)))
1713
x
1814
}
1915

R/autoplot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ top_coefs <- function(x, top_n = 5) {
8181
dplyr::slice(1) %>%
8282
dplyr::ungroup() %>%
8383
dplyr::arrange(dplyr::desc(abs(estimate))) %>%
84-
dplyr::slice(1:top_n)
84+
dplyr::slice(seq_len(top_n))
8585
}
8686

8787
autoplot_glmnet <- function(x, min_penalty = 0, best_penalty = NULL, top_n = 3L, ...) {

R/boost_tree.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ as_xgb_data <- function(x, y, validation = 0, weights = NULL, event_level = "fir
434434
if (validation > 0) {
435435
# Split data
436436
m <- floor(n * (1 - validation)) + 1
437-
trn_index <- sample(1:n, size = max(m, 2))
437+
trn_index <- sample(seq_len(n), size = max(m, 2))
438438
val_data <- xgboost::xgb.DMatrix(x[-trn_index,], label = y[-trn_index], missing = NA)
439439
watch_list <- list(validation = val_data)
440440

@@ -526,7 +526,7 @@ xgb_by_tree <- function(tree, object, new_data, type, ...) {
526526
nms <- names(pred)
527527
}
528528
pred[["trees"]] <- tree
529-
pred[[".row"]] <- 1:nrow(new_data)
529+
pred[[".row"]] <- seq_len(nrow(new_data))
530530
pred[, c(".row", "trees", nms)]
531531
}
532532

@@ -635,7 +635,7 @@ C50_by_tree <- function(tree, object, new_data, type, ...) {
635635
}
636636
nms <- names(pred)
637637
pred[["trees"]] <- tree
638-
pred[[".row"]] <- 1:nrow(new_data)
638+
pred[[".row"]] <- seq_len(nrow(new_data))
639639
pred[, c(".row", "trees", nms)]
640640
}
641641

R/mars.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,6 @@ earth_by_terms <- function(num_terms, object, new_data, type, ...) {
199199
pred <- predict(object, new_data = new_data, type = type)
200200
nms <- names(pred)
201201
pred[["num_terms"]] <- num_terms
202-
pred[[".row"]] <- 1:nrow(new_data)
202+
pred[[".row"]] <- seq_len(nrow(new_data))
203203
pred[, c(".row", "num_terms", nms)]
204204
}

R/misc.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ names0 <- function(num, prefix = "x") {
292292
if (num < 1) {
293293
rlang::abort("`num` should be > 0.")
294294
}
295-
ind <- format(1:num)
295+
ind <- format(seq_len(num))
296296
ind <- gsub(" ", "0", ind)
297297
paste0(prefix, ind)
298298
}

R/mlp.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ multi_predict._torch_mlp <-
384384
purrr::map(epochs,
385385
~ predict(object, new_data, type, epochs = .x) %>%
386386
dplyr::mutate(epochs = .x)) %>%
387-
purrr::map(~ .x %>% dplyr::mutate(.row = 1:nrow(new_data))) %>%
387+
purrr::map(~ .x %>% dplyr::mutate(.row = seq_len(nrow(new_data)))) %>%
388388
purrr::list_rbind() %>%
389389
dplyr::arrange(.row, epochs)
390390
res <- split(dplyr::select(res, -.row), res$.row)

R/surv_reg.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ survreg_quant <- function(results, object) {
115115
results <-
116116
results %>%
117117
as_tibble() %>%
118-
mutate(.row = 1:n) %>%
118+
mutate(.row = seq_len(n)) %>%
119119
gather(.label, .pred, -.row) %>%
120120
arrange(.row, .label) %>%
121121
mutate(.quantile = rep(pctl, n)) %>%

0 commit comments

Comments
 (0)