Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only pass environment into glue #346

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand, dropping this line makes sense because pmtables doesn't carry/package any vignettes under vignettes/. (There are some vignettes, but those are in inst/vignette/, which is not included in the package.)

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")
})
Loading