Skip to content

Commit d4ee6d0

Browse files
committed
docs: implements @gogonzo suggestions and cleans up docs
1 parent 0a64498 commit d4ee6d0

File tree

9 files changed

+93
-14
lines changed

9 files changed

+93
-14
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Collate:
6666
'qenv-length.R'
6767
'qenv-show.R'
6868
'qenv-within.R'
69+
'qenv-z-environment.R'
6970
'teal.code-package.R'
7071
'utils-get_code_dependency.R'
7172
'utils.R'

R/qenv-constructor.R

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@
1414
#' `new_qenv()` (`r badge("deprecated")` and not recommended)
1515
#' can instantiate a `qenv` object with data in the environment and code registered.
1616
#'
17+
#' @section Extracting objects from `qenv`:
18+
#'
19+
#' Extracting an object from the `qenv` by name can be done using the following methods:
20+
#'
21+
#' - `x[[name]]`
22+
#' - `x$name`
23+
#' - `get(name, envir = x)`
24+
#'
25+
#' note: `get_var(name)` was superseded by the native \R methods above.
26+
#'
27+
#' To list all objects in the environment, use `ls(x)` (which doesn't show
28+
#' objects that have a dot prefix with default arguments) or `names(x)` (shows all objects).
29+
#'
1730
#' @section Environment:
1831
#'
1932
#' The `qenv` object behaves like an environment that is locked and one can use
@@ -38,7 +51,6 @@ qenv <- function() {
3851
methods::new("qenv")
3952
}
4053

41-
4254
#' @param code `r badge("deprecated")`
4355
#' (`character(1)` or `language`) code to evaluate. Accepts and stores comments also.
4456
#' @param env `r badge("deprecated")` (`environment`)

R/qenv-eval_code.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#' Evaluate code in `qenv`
22
#'
33
#' @details
4-
#' `eval_code` evaluates given code in the `qenv` environment and appends it to the `code` slot.
4+
#' `eval_code()` evaluates given code in the `qenv` environment and appends it to the `code` slot.
55
#' Thus, if the `qenv` had been instantiated empty, contents of the environment are always a result of the stored code.
66
#'
77
#' @param object (`qenv`)

R/qenv-get_code.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#' Get code from `qenv`
22
#'
33
#' @details
4-
#' `get_code` retrieves the code stored in the `qenv`. `...` passes arguments to methods.
4+
#' `get_code()` retrieves the code stored in the `qenv`. `...` passes arguments to methods.
55
#'
66
#' @param object (`qenv`)
77
#' @param deparse (`logical(1)`) flag specifying whether to return code as `character` or `expression`.

R/qenv-get_var.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#' Get object from `qenv`
22
#'
3+
#' @description
4+
#' `r lifecycle::badge("superseded")` by native \R operators/functions:
5+
#' `x[[name]]`, `x$name` or `get(name, envir = qenv)`.
6+
#'
37
#' Retrieve variables from the `qenv` environment.
48
#'
59
#' @param object,x (`qenv`)
@@ -12,7 +16,6 @@
1216
#' q1 <- eval_code(q, code = quote(a <- 1))
1317
#' q2 <- eval_code(q1, code = "b <- a")
1418
#' get_var(q2, "b")
15-
#' q2[["b"]]
1619
#'
1720
#' @name get_var
1821
#' @rdname get_var
@@ -43,7 +46,6 @@ setMethod("get_var", signature = c("qenv.error", "ANY"), function(object, var) {
4346
))
4447
})
4548

46-
#' @rdname get_var
4749
setMethod("[[", signature = c("qenv", "ANY"), function(x, i) {
4850
get_var(x, i)
4951
})

R/qenv-within.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#' Evaluate Expression in `qenv`
22
#'
33
#' @details
4-
#' `within` is a convenience function for evaluating inline code inside the environment of a `qenv`.
4+
#' `within()` is a convenience function for evaluating inline code inside the environment of a `qenv`.
55
#' It is a method for the `base` generic that wraps `eval_code` to provide a simplified way of passing code.
66
#' `within` accepts only inline expressions (both simple and compound) and allows for injecting values into `expr`
77
#' through the `...` argument:

R/qenv-z-environment.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#' @name qenv-inheritted
2+
#' @rdname qenv
3+
#'
4+
#' @param x (`qenv`) object.
5+
#' @param name (`character`) name of object.
6+
#' @param pos,envir,all.names,pattern,sorted see [ls()] function for details.
7+
#'
8+
#' @usage x[[name]]
9+
#' x$name
10+
#' names(x)
11+
#' ls(name, pos = -1L, envir = as.environment(pos),
12+
#' all.names = FALSE, pattern, sorted = TRUE)
13+
#'
14+
#' @details
15+
#' `x[[name]]`, `x$name` and `get(name, x)` are generic \R operators to access the objects in the environment.
16+
#' See [`[[`] for more details.
17+
#' `names(x)` and `ls(x)` calls on the `qenv` object and will list all objects in the environment.
18+
#'
19+
#' @return `[[`, `$` and `get` return the value of the object named `name` in the `qenv` object.
20+
#' @return `names` return a character vector of all the names of the objects in the `qenv` object.
21+
#' @return `ls` return a character vector of the names of the objects in the `qenv` object.
22+
#' It will only show the objects that are not named with a dot prefix, unless
23+
#' the `all.names = TRUE`, which will show all objects.
24+
NULL

man/get_var.Rd

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/qenv.Rd

Lines changed: 45 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)