From 81049330475afb57ac2333e7a18d86399d2b9843 Mon Sep 17 00:00:00 2001 From: Duncan Murdoch Date: Thu, 29 Aug 2024 08:35:22 -0400 Subject: [PATCH] Another fix. --- R/tabular.R | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/R/tabular.R b/R/tabular.R index 03198f7..a42a6e2 100644 --- a/R/tabular.R +++ b/R/tabular.R @@ -629,8 +629,19 @@ tabular.formula <- function(table, data=NULL, n, suppressLabels=0, ...) { if (missing(n) && inherits(data, "data.frame")) n <- nrow(data) - if (is.null(data)) - data <- environment(table) + # We need access to labelSubset() (and perhaps other functions in future) + # when evaluating a table expression (issue #30), but we don't want + # to mask the user's copy. + + parent <- if (is.environment(data)) data else environment(table) + if (!exists("labelSubset", envir = parent)) { + withTableFns <- new.env(parent = parent) + withTableFns$labelSubset <- labelSubset + } else + withTableFns <- parent + + if (is.null(data) || is.environment(data)) + data <- withTableFns else if (is.list(data)) data <- list2env(data, parent = environment(table)) else if (!is.environment(data))