Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
Expand Up @@ -28,13 +28,13 @@ Depends:
R (>= 4.0)
Imports:
checkmate (>= 2.1.0),
cli (>= 3.4.0),
grDevices,
lifecycle (>= 0.2.0),
rlang (>= 1.1.0),
stats,
utils
Suggests:
cli (>= 3.4.0),
knitr (>= 1.42),
rmarkdown (>= 2.23),
shiny (>= 1.6.0),
Expand Down
2 changes: 1 addition & 1 deletion R/qenv-constructor.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' and [within.qenv()] functions.
#' - It stores metadata about the code used to create the data (see [get_code()]).
#' - It supports slicing (see [`subset-qenv`])
#' - Is immutable which means that each code evaluation does not modify the original `qenv`
#' - It is immutable which means that each code evaluation does not modify the original `qenv`
#' environment directly. See the following code:
#'
#' ```
Expand Down
2 changes: 1 addition & 1 deletion R/qenv-eval_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' `expression` being a result of `parse(keep.source = TRUE)`.
#'
#' @return
#' Returns a `qenv` object with `code/expr` evaluated or `qenv.error` if evaluation fails.
#' `qenv` environment with `code/expr` evaluated or `qenv.error` if evaluation fails.
#'
#' @examples
#' # evaluate code in qenv
Expand Down
2 changes: 1 addition & 1 deletion R/qenv-get_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
#' - creating and evaluating language objects, _e.g._ `eval(<call>)`
#'
#' @return
#' Returns the traced code in the form specified by `deparse`.
#' The code used in the `qenv` in the form specified by `deparse`.
#'
#' @examples
#' # retrieve code
Expand Down
23 changes: 22 additions & 1 deletion R/qenv-show.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,26 @@
#' @importFrom methods show
#' @export
setMethod("show", "qenv", function(object) {
rlang::env_print(object@.xData)
env <- get_env(object)
header <- cli::col_blue(sprintf("<environment: %s>", rlang::env_label(env)))
locked <- if (environmentIsLocked(env)) {
" [L]"
} else {
""
}
parent <- sprintf("Parent: <environment: %s>", rlang::env_label(rlang::env_parent(env)))
cat(cli::style_bold(paste0(header, locked)), sep = "\n")
cat(parent, "\n")

shown <- ls(object)
lapply(shown, function(x) {
cat(sprintf("- %s: [%s]\n", x, class(object[[x]])[1]))
})

hidden <- setdiff(ls(object, all.names = TRUE), shown)
lapply(hidden, function(x) {
cat(cli::style_blurred(sprintf("- %s: [%s]\n", x, class(object[[x]])[1])))
})

invisible(object)
})
7 changes: 3 additions & 4 deletions R/qenv-within.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#' @details
#' `within()` is a convenience method that wraps `eval_code` to provide a simplified way of passing expression.
#' `within` accepts only inline expressions (both simple and compound) and allows to substitute `expr`
#' with the `...` argument values.
#' with `...` named argument values.
#'
#' @section Using language objects with `within`:
#' Passing language objects to `expr` is generally not intended but can be achieved with `do.call`.
#' Only single `expression`s will work and substitution is not available. See examples.
#'
#' @param data (`qenv`)
#' @param expr (`expression`) to evaluate. Must be inline code, see `Using language objects...`
#' @param ... (`named`) argument value will substitute a symbol in the `expr` matched by the name.
#' For practical examples see the #usage.
#'
#' @param ... named argument value will substitute a symbol in the `expr` matched by the name.
#' For practical usage see Examples section below.
#'
#' @examples
#' # evaluate code using within
Expand Down
8 changes: 4 additions & 4 deletions man/eval_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/get_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/qenv.Rd

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

2 changes: 1 addition & 1 deletion vignettes/qenv.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ A `qenv` inherits from the `environment` class, behaves like an environment, and
- `qenv` is a locked environment, and data modification is only possible through the `eval_code` and `within` functions.
- It stores metadata about the code used to create the data (see `get_code`).
- It supports slicing by `[`.
- Is immutable which means that each code evaluation does not modify the original `qenv` environment directly.
- It is immutable which means that each code evaluation does not modify the original `qenv` environment directly.

### Initialization

Expand Down
Loading