diff --git a/R/Apply.R b/R/Apply.R index 080af96175f22bd45656ef7d5308c9b80fe93c67..584787ce7f96fac48ac342e9bcae6ca96a38b6fa 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))