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

Passing environment as an argument to eng_r #2358

Merged
merged 9 commits into from
Nov 1, 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
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.48.7
Version: 1.48.8
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- Added support for `fig.alt` for LaTeX output, i.e., using `\includegraphics[alt={alt text}]` (thanks, @capnrefsmmat, #2378).

- The environment in which code chunks are evaluated can be changed by passing a custom environment to `knit_glbal()` now (thanks, @abhsarma, #2358).

## BUG FIXES

- In-chunk references of the form `<<label>>` should not be resolved if `label` is not found in the document (thanks, @jennybc @gadenbuie, #2360).
Expand Down
19 changes: 10 additions & 9 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -561,18 +561,19 @@ fig_chunk = function(label, ext = '', number, fig.path = opts_chunk$get('fig.pat
fig_path(ext, list(fig.path = fig.path, label = label), number)
}

#' The global environment in which code chunks are evaluated
#' The global environment for evaluating code
#'
#' This function makes the environment of a code chunk accessible inside a
#' chunk.
#' Get or set the environment in which code chunks are evaluated.
#'
#' It returns the \code{envir} argument of \code{\link{knit}}, e.g. if we call
#' \code{\link{knit}()} in the global environment, \code{knit_global()} returns
#' R's global environment by default. You can call functions like
#' \code{\link{ls}()} on this environment.
#' @param envir If \code{NULL}, the function returns the \code{envir} argument
#' of \code{\link{knit}}, otherwise it should be a new environment for
#' evaluating code, in which case the function returns the old environment
#' after setting the new environment.
#' @export
knit_global = function() {
.knitEnv$knit_global %n% globalenv()
knit_global = function(envir = NULL) {
old = .knitEnv$knit_global %n% globalenv()
if (!is.null(envir)) .knitEnv$knit_global = envir
old
}

# Indents a Block
Expand Down
19 changes: 9 additions & 10 deletions man/knit_global.Rd

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