From 239db331dcdf186d7b2c16a0b62025a5424c24f4 Mon Sep 17 00:00:00 2001 From: asardaes Date: Sun, 23 Jun 2024 01:01:57 +0200 Subject: [PATCH] Refactor quoted_call to not obscure so much --- .github/workflows/check-non-master.yaml | 5 ----- NAMESPACE | 3 +++ R/UTILS-utils.R | 18 ++++++++++++++++-- tests/testthat/unit/methods.R | 2 +- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.github/workflows/check-non-master.yaml b/.github/workflows/check-non-master.yaml index 5eed1af2..c79917bd 100644 --- a/.github/workflows/check-non-master.yaml +++ b/.github/workflows/check-non-master.yaml @@ -1,9 +1,4 @@ -# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag. -# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions on: - push: - branches-ignore: - - master pull_request: branches: - master diff --git a/NAMESPACE b/NAMESPACE index f03232a2..22569d42 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -125,9 +125,12 @@ importFrom(reshape2,melt) importFrom(rlang,"!!!") importFrom(rlang,.data) importFrom(rlang,as_environment) +importFrom(rlang,as_string) +importFrom(rlang,enexpr) importFrom(rlang,enexprs) importFrom(rlang,env_bind) importFrom(rlang,exprs) +importFrom(rlang,is_call) importFrom(rlang,list2) importFrom(rlang,syms) importFrom(shiny,runApp) diff --git a/R/UTILS-utils.R b/R/UTILS-utils.R index ca3bbe65..1ef59788 100644 --- a/R/UTILS-utils.R +++ b/R/UTILS-utils.R @@ -137,9 +137,23 @@ get_from_callers <- function(obj_name, mode = "any") { } #' @importFrom rlang as_environment +#' @importFrom rlang as_string +#' @importFrom rlang enexpr +#' @importFrom rlang is_call quoted_call <- function(fun, ..., dots = NULL) { - parent <- rlang::as_environment(list(.fun_ = match.fun(fun)), parent = parent.frame()) - do_call(".fun_", enlist(..., dots = dots), parent = parent) + fun_expr <- rlang::enexpr(fun) + fun_name <- if (rlang::is_call(fun_expr)) { + fn <- as.character(fun_expr) + paste0(fn[2L], fn[1L], fn[3L], collapse = "") + } else { + rlang::as_string(fun_expr) + } + fun_name <- gsub("[@$:]", "_", fun_name) + + l <- list(match.fun(fun)) + names(l) <- fun_name + parent <- rlang::as_environment(l, parent = parent.frame()) + do_call(fun_name, enlist(..., dots = dots), parent = parent) } #' @importFrom rlang as_environment diff --git a/tests/testthat/unit/methods.R b/tests/testthat/unit/methods.R index 3d8c9cb4..e2b23c46 100644 --- a/tests/testthat/unit/methods.R +++ b/tests/testthat/unit/methods.R @@ -274,7 +274,7 @@ test_that("Methods for TSClusters objects are dispatched correctly.", { info = "Plotting series and centroids providing data returns a gg object invisibly") expect_true(inherits(plot(fuzzy_object, type = "series", plot = FALSE, labels = list()), "ggplot"), info = "Plotting multivariate series returns a gg object invisibly") - expect_s3_class(plot(tadpole_object, plot = FALSE, size = 1.5), "ggplot") + expect_s3_class(plot(tadpole_object, plot = FALSE, linewidth = 1.5), "ggplot") object_with_repeated_series <- partitional_object object_with_repeated_series@datalist[[1L]] <- object_with_repeated_series@datalist[[2L]]