Skip to content

Commit 1a8bab3

Browse files
Replace tibbles with data frames to improve performance (#1007)
* as_tibble -> as.data.frame * new_tibble -> data.frame * pre-commit * Update utils.R * Update ui-caching.R * encapsulate in wrappers around vctrs functions * Add vctrs to DESCRIPTION * pre-commit * Update utils.R * Update compat-dplyr.R * Update detect-alignment.Rmd * Don't import entire tibble package Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 1f4437b commit 1a8bab3

31 files changed

+575
-572
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Imports:
3434
rprojroot (>= 1.1),
3535
tibble (>= 1.4.2),
3636
tools,
37+
vctrs (>= 0.4.1),
3738
withr (>= 1.0.0),
3839
Suggests:
3940
data.tree (>= 0.1.6),

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export(style_text)
1717
export(tidyverse_math_token_spacing)
1818
export(tidyverse_reindention)
1919
export(tidyverse_style)
20-
import(tibble)
2120
importFrom(magrittr,"%>%")
2221
importFrom(magrittr,or)
2322
importFrom(magrittr,set_names)
@@ -43,6 +42,7 @@ importFrom(rlang,is_installed)
4342
importFrom(rlang,seq2)
4443
importFrom(rlang,warn)
4544
importFrom(rlang,with_handlers)
45+
importFrom(tibble,tribble)
4646
importFrom(utils,capture.output)
4747
importFrom(utils,tail)
4848
importFrom(utils,write.table)

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()))
29+
return(new_styler_df(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)
65+
res <- new_styler_df(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)
9+
new_styler_df(res)
1010
}

R/nest.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ add_terminal_token_after <- function(pd_flat) {
249249
filter(terminal) %>%
250250
arrange_pos_id()
251251

252-
rhs <- new_tibble(
252+
rhs <- new_styler_df(
253253
list(
254254
pos_id = terminals$pos_id,
255255
token_after = lead(terminals$token, default = "")
@@ -266,7 +266,7 @@ add_terminal_token_before <- function(pd_flat) {
266266
filter(terminal) %>%
267267
arrange_pos_id()
268268

269-
rhs <- new_tibble(
269+
rhs <- new_styler_df(
270270
list(
271271
id = terminals$id,
272272
token_before = lag(terminals$token, default = "")

R/nested-to-tree.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ create_tree_from_pd_with_default_style_attributes <- function(pd,
1616
structure_only = FALSE) {
1717
pd %>%
1818
create_node_from_nested_root(structure_only) %>%
19+
# don't use `styler_df()` here; `vctrs::data_frame()` only accepts a vector, not a <Node/R6> object
1920
as.data.frame()
2021
}
2122

R/parse.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ get_parse_data <- function(text, include_text = TRUE, ...) {
9494
# avoid https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=16041
9595
parse_safely(text, keep.source = TRUE)
9696
parsed <- parse_safely(text, keep.source = TRUE)
97-
pd <- as_tibble(
97+
pd <- styler_df(
9898
utils::getParseData(parsed, includeText = include_text),
9999
.name_repair = "minimal"
100100
)
@@ -163,7 +163,7 @@ ensure_correct_txt <- function(pd, text) {
163163
by.y = "id",
164164
suffixes = c("", "parent")
165165
) %>%
166-
as_tibble(.name_repair = "minimal")
166+
styler_df(.name_repair = "minimal")
167167

168168
if (!lines_and_cols_match(new_text)) {
169169
abort(paste(

R/style-guides.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ tidyverse_style <- function(scope = "tokens",
315315
#' }
316316
#' set_line_break_before_curly_opening_style <- function() {
317317
#' create_style_guide(
318-
#' line_break = tibble::lst(set_line_break_before_curly_opening),
318+
#' line_break = list(set_line_break_before_curly_opening),
319319
#' style_guide_name = "some-style-guide",
320320
#' style_guide_version = "some-version"
321321
#' )

R/stylerignore.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ apply_stylerignore <- function(flattened_pd) {
123123
env_current$stylerignore[, colnames_required_apply_stylerignore],
124124
by.x = "pos_id", by.y = "first_pos_id_in_segment", all.x = TRUE,
125125
sort = FALSE
126-
) %>%
127-
as_tibble()
126+
)
127+
128128
flattened_pd %>%
129129
stylerignore_consolidate_col("lag_newlines") %>%
130130
stylerignore_consolidate_col("lag_spaces") %>%

R/token-create.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ create_tokens <- function(tokens,
3939
block = NA,
4040
is_cached = FALSE) {
4141
len_text <- length(texts)
42-
new_tibble(
42+
new_styler_df(
4343
list(
4444
token = tokens,
4545
text = texts,

0 commit comments

Comments
 (0)