Skip to content

Commit 32702ae

Browse files
Don't use nrow arg in new_tibble() calls (#1003)
* Don't use `nrow` arg in `new_tibble()` calls We are unnecessarily repeating ourselves by doing this. * simplify further * pre-commit * revert Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 08da821 commit 32702ae

File tree

6 files changed

+9
-12
lines changed

6 files changed

+9
-12
lines changed

R/compat-dplyr.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ arrange_pos_id <- function(data) {
2626

2727
bind_rows <- function(x, y = NULL, ...) {
2828
if (is.null(x) && is.null(y)) {
29-
return(new_tibble(list(), nrow = 0))
29+
return(new_tibble(list()))
3030
}
3131
if (is.null(x)) {
3232
if (inherits(y, "data.frame")) {
@@ -62,7 +62,7 @@ left_join <- function(x, y, by) {
6262

6363
res <- merge(x, y, by.x = by_x, by.y = by_y, all.x = TRUE, sort = FALSE) %>%
6464
arrange_pos_id()
65-
res <- new_tibble(res, nrow = nrow(res))
65+
res <- new_tibble(res)
6666
# dplyr::left_join set unknown list columns to NULL, merge sets them
6767
# to NA
6868
if (exists("child", res) && anyNA(res$child)) {

R/compat-tidyr.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ nest_ <- function(data, key_col, nest_cols = character()) {
66
res <- list()
77
res[[key_column]] <- key_levels
88
res[[key_col]] <- split(data[, nest_cols], key_factor)
9-
new_tibble(res, nrow = length(key_levels))
9+
new_tibble(res)
1010
}

R/nest.R

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,7 @@ add_terminal_token_after <- function(pd_flat) {
253253
list(
254254
pos_id = terminals$pos_id,
255255
token_after = lead(terminals$token, default = "")
256-
),
257-
nrow = nrow(terminals)
256+
)
258257
)
259258

260259
left_join(pd_flat, rhs, by = "pos_id")
@@ -271,8 +270,7 @@ add_terminal_token_before <- function(pd_flat) {
271270
list(
272271
id = terminals$id,
273272
token_before = lag(terminals$token, default = "")
274-
),
275-
nrow = nrow(terminals)
273+
)
276274
)
277275

278276
left_join(pd_flat, rhs, by = "id")

R/token-create.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ create_tokens <- function(tokens,
5959
stylerignore = stylerignore,
6060
block = block,
6161
is_cached = is_cached
62-
),
63-
nrow = len_text
62+
)
6463
)
6564
}
6665

@@ -78,7 +77,7 @@ create_tokens <- function(tokens,
7877
#' create one. The validation is done with [validate_new_pos_ids()]
7978
#' @family token creators
8079
#' @keywords internal
81-
create_pos_ids <- function(pd, pos, by = 0.1, after = FALSE, n = 1) {
80+
create_pos_ids <- function(pd, pos, by = 0.1, after = FALSE, n = 1L) {
8281
direction <- ifelse(after, 1L, -1L)
8382
first <- find_start_pos_id(pd, pos, by, direction, after)
8483
new_ids <- seq(first,

R/transform-files.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ transform_files <- function(files,
3030
)
3131
communicate_summary(changed, max_char)
3232
communicate_warning(changed, transformers)
33-
new_tibble(list(file = files, changed = changed), nrow = len_files)
33+
new_tibble(list(file = files, changed = changed))
3434
}
3535

3636
#' Transform a file and output a customized message

man/create_pos_ids.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)