Skip to content

Commit

Permalink
use a different method to fix #1798 because R CMD check doesn't like …
Browse files Browse the repository at this point in the history
…the unlockBinding() call
  • Loading branch information
yihui committed Sep 7, 2023
1 parent 43dd3ae commit d9b5be6
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: knitr
Type: Package
Title: A General-Purpose Package for Dynamic Report Generation in R
Version: 1.43.16
Version: 1.43.17
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")),
person("Abhraneel", "Sarma", role = "ctb"),
Expand Down
4 changes: 2 additions & 2 deletions R/block.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ call_block = function(block) {
}

# save current chunk options in opts_current
opts_current$unlock(); opts_current$restore(params)
opts_current$restore(params)

if (opts_knit$get('progress')) print(block)

Expand Down Expand Up @@ -112,7 +112,7 @@ call_block = function(block) {
opts_current$restore(params) # save current options
# prevent users from modifying opts_current (#1798)
if (!xfun::check_old_package('lingglosses', '0.0.6')) # TODO: remove this hack https://github.com/agricolamz/lingglosses/issues/22
opts_current$lock(); on.exit(opts_current$unlock(), add = TRUE)
opts_current$lock(); on.exit(opts_current$lock(FALSE), add = TRUE)

# set local options() for the current R chunk
if (is.list(params$R.options)) {
Expand Down
12 changes: 7 additions & 5 deletions R/defaults.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

new_defaults = function(value = list()) {
defaults = value
locked = FALSE

get = function(name, default = FALSE, drop = TRUE) {
if (default) defaults = value # this is only a local version
Expand All @@ -20,7 +21,10 @@ new_defaults = function(value = list()) {
}
set2 = function(values) {
old = get(names(values), drop = FALSE)
if (length(values)) defaults <<- merge(values)
if (length(values)) {
if (locked) stop('The object is read-only and cannot be modified.')
defaults <<- merge(values)
}
invisible(old)
}
set = function(...) {
Expand All @@ -36,13 +40,11 @@ new_defaults = function(value = list()) {
for (i in names(dots)) dots[[i]] <- c(defaults[[i]], dots[[i]])
set2(dots)
}
env = environment()
lock = function() lockBinding('defaults', env)
unlock = function() unlockBinding('defaults', env)
lock = function(status = TRUE) locked <<- status

list(
get = get, set = set, delete = delete, append = append, merge = merge,
restore = restore, lock = lock, unlock = unlock
restore = restore, lock = lock
)
}

Expand Down
2 changes: 1 addition & 1 deletion R/output.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ knit = function(
on.exit({
opts_chunk$restore(optc)
knit_code$restore(ocode)
opts_current$unlock(); opts_current$restore()
opts_current$restore()
opts_knit$restore(optk)
}, add = TRUE)
opts_knit$set(
Expand Down
2 changes: 1 addition & 1 deletion man/cache_engines.Rd

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

2 changes: 1 addition & 1 deletion man/knit_code.Rd

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

2 changes: 1 addition & 1 deletion man/knit_engines.Rd

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

2 changes: 1 addition & 1 deletion man/knit_hooks.Rd

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

2 changes: 1 addition & 1 deletion man/knit_patterns.Rd

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

4 changes: 2 additions & 2 deletions man/opts_chunk.Rd

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

2 changes: 1 addition & 1 deletion man/opts_hooks.Rd

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

2 changes: 1 addition & 1 deletion man/opts_knit.Rd

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

2 changes: 1 addition & 1 deletion man/opts_template.Rd

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

0 comments on commit d9b5be6

Please sign in to comment.