Skip to content

Commit

Permalink
Merge pull request #346 from metrumresearchgroup/fix/glue
Browse files Browse the repository at this point in the history
Only pass environment into glue
  • Loading branch information
kylebaron authored Oct 23, 2024
2 parents 4f45a74 + ffac7fd commit 863b764
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 15 deletions.
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ Suggests: testthat, yaml, texPreview, magick, pdftools, withr
Encoding: UTF-8
Language: en-US
LazyData: true
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Roxygen: list(markdown = TRUE)
VignetteBuilder: knitr
Collate:
'class-new_names.R'
'class-digits.R'
Expand Down
4 changes: 1 addition & 3 deletions R/AAAA.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,8 @@ find_cached_root <- function() {
#
#'
#' @md
#' @docType package
#' @name pmtables
NULL

"_PACKAGE"

#' Load an example data set
#'
Expand Down
17 changes: 8 additions & 9 deletions R/preview-standalone.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,14 @@ st_to_standalone <- function(text, stem, dir,
vwidth <- ""
}

env <- list(
border = border,
texfile = texfile,
font = fonts[[font]],
textw_tex = as.character(textw_tex),
rule = rule,
vwidth = vwidth,
ltversion = paste0("[=v", ltversion, "]%")
)
env <- new.env()
env$border <- border
env$texfile <- texfile
env$font <- fonts[[font]]
env$textw_tex <- as.character(textw_tex)
env$rule <- rule
env$vwidth <- vwidth
env$ltversion <- paste0("[=v", ltversion, "]%")

temp_text <- mgluet(temp_text, .envir = env)
build_file <- basename(temp_file)
Expand Down
2 changes: 1 addition & 1 deletion R/preview.R
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ st2article <- function(..., .list = NULL, ntex = 1, #nocov start

temp <- readLines(template)

env <- list()
env <- new.env()
env$list_of_tables <- c("\\listoftables", "\\clearpage")
env$input_file <- st2article_input
env$hmargin <- margin[1]
Expand Down
3 changes: 3 additions & 0 deletions R/table-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ require_col <- function(data,col,context=NULL) {

gluet <- function(x, .envir = parent.frame(), ...) {
x <- force(x)
if(!is.environment(.envir)) {
abort("pmtables error: cannot `glue()` - .envir is not an environment.")
}
glue(x,.open = "<", .close = ">", .envir = .envir)
}

Expand Down
22 changes: 22 additions & 0 deletions man/pmtables.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/testthat/test-table-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,12 @@ test_that("table-utils paste units [PMT-TEST-0239]", {
c("B mg", "E", "D kg", "C pounds", "A")
)
})

test_that("error is generated when calling gluet with non-environment", {
x <- list(a = 1, b = 2, c = 3)
what <- "<b><a><c>"
expect_error(pmtables:::gluet(what, .envir = x), "pmtables error:")
env <- as.environment(x)
ans <- pmtables:::gluet(what, .envir = env)
expect_identical(unclass(ans), "213")
})

0 comments on commit 863b764

Please sign in to comment.