From 4b0d9d34469a01a9696ebc8be0fda8f7820dd296 Mon Sep 17 00:00:00 2001 From: vagudets Date: Wed, 7 May 2025 09:45:02 +0200 Subject: [PATCH] Only apply environment() to 'closure' type functions --- R/Apply.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/Apply.R b/R/Apply.R index 080af96..584787c 100644 --- a/R/Apply.R +++ b/R/Apply.R @@ -613,7 +613,10 @@ Apply <- function(data, target_dims = NULL, fun, ..., for (i in seq_along(extra_info)) { assign(names(extra_info)[i], extra_info[[i]], envir = fun_env) } - environment(fun) <- fun_env + # Modify function environment if it is not a primitive function + if (typeof(fun) == "closure") { + environment(fun) <- fun_env + } splatted_f <- splat(fun) input_margin_weights <- vector('list', length(data)) -- GitLab