From c4fb6c819f53317a07f18c5b3ded5dffda441969 Mon Sep 17 00:00:00 2001 From: Jari Oksanen Date: Fri, 26 Apr 2024 14:12:38 +0300 Subject: [PATCH] adonis2: eval lhs primarily within parent.frame() Evaluating within environment(formula) fails if adonis2 is embedded and data are manipulated within embedding parent function. Problem found with betaper::adonis_pertables(). --- R/adonis.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/adonis.R b/R/adonis.R index 6b8e9dd1d..d375f76c9 100644 --- a/R/adonis.R +++ b/R/adonis.R @@ -13,7 +13,7 @@ by <- match.arg(by, c("terms", "margin", "onedf")) ## evaluate lhs YVAR <- formula[[2]] - lhs <- eval(YVAR, environment(formula), globalenv()) + lhs <- eval(YVAR, parent.frame(), environment(formula)) environment(formula) <- environment() ## Take care that input lhs are dissimilarities if ((is.matrix(lhs) || is.data.frame(lhs)) &&