Skip to content

Commit

Permalink
Better fix for issue #30.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmurdoch committed Aug 24, 2024
1 parent b44f4fe commit 7a041cb
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions R/tabular.R
Original file line number Diff line number Diff line change
Expand Up @@ -629,15 +629,21 @@ tabular.formula <- function(table, data=NULL, n, suppressLabels=0, ...) {
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)
# 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

withTableFns <- new.env(parent = if (is.environment(data)) data else environment(table))
withTableFns$labelSubset <- labelSubset
if (is.null(data))
data <- withTableFns
else if (is.list(data))
data <- list2env(data, parent=withTableFns)
data <- list2env(data, parent = withTableFns)
else if (!is.environment(data))
stop("'data' must be a dataframe, list or environment")

Expand Down

0 comments on commit 7a041cb

Please sign in to comment.