From 0088bbc0d1e6742993d231a884572ef141b70b68 Mon Sep 17 00:00:00 2001 From: Duncan Murdoch Date: Thu, 22 Aug 2024 19:06:53 -0400 Subject: [PATCH] Don't assume we are on the search list. --- DESCRIPTION | 2 +- NEWS.md | 4 +++- R/tabular.R | 10 ++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4c0e9be..772d6aa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: tables Title: Formula-Driven Table Generation -Version: 0.9.29 +Version: 0.9.30 Author: Duncan Murdoch Description: Computes and displays complex tables of summary statistics. Output may be in LaTeX, HTML, plain text, or an R diff --git a/NEWS.md b/NEWS.md index e57f64a..ac116d9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,8 +1,10 @@ -# tables 0.9.29 +# tables 0.9.30 - In a few places `len` was used instead of `length.out` in calls to `rep()`, leading to warnings. Similarly, `rep` was used instead of `replace` in `sample()` (issue #28). +- `tabular` assumed it was on the search list, and didn't work when +called as `tables::tabular` (issue #30). # tables 0.9.28 diff --git a/R/tabular.R b/R/tabular.R index 6e761a1..16aedd9 100644 --- a/R/tabular.R +++ b/R/tabular.R @@ -628,10 +628,16 @@ tabular.formula <- function(table, data=NULL, n, suppressLabels=0, ...) { domain = NA) if (missing(n) && inherits(data, "data.frame")) n <- nrow(data) + + # We need access to labelSubset() (and perhaps other functions) + # when evaluating a table expression. (Issue #30) + + withTableFns <- new.env(parent = if (is.environment(data)) data else environment(table)) + withTableFns$labelSubset <- labelSubset if (is.null(data)) - data <- environment(table) + data <- withTableFns else if (is.list(data)) - data <- list2env(data, parent=environment(table)) + data <- list2env(data, parent=withTableFns) else if (!is.environment(data)) stop("'data' must be a dataframe, list or environment")