Skip to content

Commit

Permalink
fix(with_epoxy_engine): Don't use withr
Browse files Browse the repository at this point in the history
  • Loading branch information
gadenbuie committed Jun 11, 2023
1 parent 4957929 commit a444fd4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
9 changes: 2 additions & 7 deletions R/epoxy.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,9 @@ epoxy_latex <- function(
}

with_epoxy_engine <- function(engine, expr) {
local_epoxy_engine(engine)
expr
}

local_epoxy_engine <- function(engine = "md", .local_envir = parent.frame()) {
withr::local_options(
with_options(
list(epoxy.engine = engine_validate_alias(engine)),
.local_envir = .local_envir
expr
)
}

Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-epoxy.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,17 @@ describe("epoxy_transform_set()", {
)
})
})

test_that("with_epoxy_engine()", {
old_opts <- options(epoxy.engine = NULL)
on.exit(options(old_opts))

expect_equal(with_epoxy_engine("html", engine_current()), "html")
expect_null(engine_current())

expect_equal(with_epoxy_engine("markdown", engine_current()), "md")
expect_null(engine_current())

expect_equal(with_epoxy_engine("latex", engine_current()), "latex")
expect_null(engine_current())
})

0 comments on commit a444fd4

Please sign in to comment.