From ae1d1d94ca6e5f57760f8a19c8bd23e627a8cb9c Mon Sep 17 00:00:00 2001 From: Nick Christofides <118103879+NicChr@users.noreply.github.com> Date: Sat, 31 Aug 2024 15:05:43 +0100 Subject: [PATCH] Sped up expression deparsing. --- R/dots.R | 2 +- R/utils.R | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/R/dots.R b/R/dots.R index 6011b7a..3dbc377 100644 --- a/R/dots.R +++ b/R/dots.R @@ -26,5 +26,5 @@ named_dots <- function(...){ dots } dot_expr_names <- function(...){ - vapply(substitute(alist(...))[-1L], deparse1, "", USE.NAMES = FALSE) + vapply(substitute(alist(...))[-1L], deparse2, "", USE.NAMES = FALSE) } diff --git a/R/utils.R b/R/utils.R index 29f4387..0296b16 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,8 +1,8 @@ #' @noRd -# Include this as it's not available in older versions of R -deparse1 <- function(expr, collapse = " ", width.cutoff = 500L, ...){ - paste(deparse(expr, width.cutoff, ...), collapse = collapse) +# Like deparse1 but has a cutoff in case of massive strings +deparse2 <- function(expr, collapse = " ", width.cutoff = 500L, nlines = 5L, ...){ + paste(deparse(expr, width.cutoff, nlines = nlines, ...), collapse = collapse) } is_integerable <- function(x){ @@ -38,12 +38,12 @@ list_as_df <- cpp_list_as_df check_length <- function(x, n){ if (length(x) != n){ - stop(paste(deparse1(substitute(x)), "must have length", n)) + stop(paste(deparse2(substitute(x)), "must have length", n)) } } check_is_df <- function(x){ if (!inherits(x, "data.frame")){ - stop(paste(deparse1(substitute(x)), "must be a data frame.")) + stop(paste(deparse2(substitute(x)), "must be a data frame.")) } } df_add_cols <- function(data, cols){