From 3061e30a5226730c88a68f1d24394b8e32f5ecb7 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Mon, 11 Jan 2021 21:53:55 +0100 Subject: [PATCH] replace loop with walk for speed --- NAMESPACE | 1 + R/transform-files.R | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 67f3fcd43..e67c8699a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -35,6 +35,7 @@ importFrom(purrr,map_lgl) importFrom(purrr,partial) importFrom(purrr,pmap) importFrom(purrr,pwalk) +importFrom(purrr,walk) importFrom(purrr,when) importFrom(rlang,abort) importFrom(rlang,is_empty) diff --git a/R/transform-files.R b/R/transform-files.R index 744ed082a..b37275f08 100644 --- a/R/transform-files.R +++ b/R/transform-files.R @@ -257,13 +257,14 @@ parse_transform_serialize_r <- function(text, #' that trigger are required to be absent to trigger a removal. #' @param scope The low-level scope, e.g. 'token'. #' @param code tokenized code for which we check if `token` is in them. +#' @importFrom purrr walk transformers_subset_impl <- function(transformers, token, scope, code) { transformer_names <- names(token) - for (i in seq_along(token)) { + walk(seq_along(token), function(i) { if (!any(token[[i]] %in% code)) { transformers[[scope]][[transformer_names[i]]] <- NULL } - } + }) transformers }