Skip to content

Commit 9d2ec00

Browse files
committed
docs: improvement on join() documentation
1 parent 50be4b0 commit 9d2ec00

File tree

3 files changed

+61
-29
lines changed

3 files changed

+61
-29
lines changed

R/qenv-c.R

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,19 @@
5050
}
5151
}
5252

53-
#' @export
54-
c.qenv.error <- function(...) {
55-
rlang::list2(...)[[1]]
56-
}
57-
53+
#' @rdname join
54+
#' @param ... (`qenv` or `qenv.error`).
55+
#' @examples
56+
#' q <- qenv()
57+
#' q1 <- within(q, {
58+
#' iris1 <- iris
59+
#' mtcars1 <- mtcars
60+
#' })
61+
#' q1 <- within(q1, iris2 <- iris)
62+
#' q2 <- within(q1, mtcars2 <- mtcars)
63+
#' qq <- c(q1, q2)
64+
#' cat(get_code(qq))
65+
#'
5866
#' @export
5967
c.qenv <- function(...) {
6068
dots <- rlang::list2(...)
@@ -91,3 +99,9 @@ c.qenv <- function(...) {
9199
}
92100
)
93101
}
102+
103+
#' @rdname join
104+
#' @export
105+
c.qenv.error <- function(...) {
106+
rlang::list2(...)[[1]]
107+
}

R/qenv-join.R

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#' Join `qenv` objects
22
#'
33
#' @description
4-
#' `r lifecycle::badge("superseded")` by [c()].
5-
#'
64
#' Checks and merges two `qenv` objects into one `qenv` object.
75
#'
6+
#' The `join()` function is superseded by the `c()` function.
7+
#'
88
#' @details
99
#' Any common code at the start of the `qenvs` is only placed once at the start of the joined `qenv`.
1010
#' This allows consistent behavior when joining `qenvs` which share a common ancestor.
@@ -19,7 +19,7 @@
1919
#' x <- eval_code(qenv(), expression(mtcars1 <- mtcars))
2020
#' y <- eval_code(qenv(), expression(mtcars1 <- mtcars['wt']))
2121
#'
22-
#' z <- join(x, y)
22+
#' z <- c(x, y)
2323
#' # Error message will occur
2424
#' ```
2525
#' In this example, `mtcars1` object exists in both `x` and `y` objects but the content are not identical.
@@ -44,8 +44,8 @@
4444
#' y,
4545
#' "z <- v"
4646
#' )
47-
#' q <- join(x, y)
48-
#' join_q <- join(q, z)
47+
#' q <- c(x, y)
48+
#' join_q <- c(q, z)
4949
#' # Error message will occur
5050
#'
5151
#' # Check the order of evaluation based on the id slot
@@ -78,10 +78,10 @@
7878
#' # Error message will occur
7979
#'
8080
#' # Check the value of temporary variable i in both objects
81-
#' x@.xData$i # Output: 2
82-
#' y@.xData$i # Output: 3
81+
#' x$i # Output: 2
82+
#' y$i # Output: 3
8383
#' ```
84-
#' `join()` fails to provide a proper result because of the temporary variable `i` exists
84+
#' `c()` and `join()` fails to provide a proper result because of the temporary variable `i` exists
8585
#' in both objects but has different value.
8686
#' To fix this, we can set `i <- NULL` in the code expression for both objects.
8787
#' ```r
@@ -104,7 +104,7 @@
104104
#' # dummy i variable to fix it
105105
#' i <- NULL"
106106
#' )
107-
#' q <- join(x,y)
107+
#' q <- c(x,y)
108108
#' ```
109109
#'
110110
#' @param x (`qenv`)
@@ -119,14 +119,14 @@
119119
#' q1 <- eval_code(q1, "iris2 <- iris")
120120
#' q2 <- eval_code(q2, "mtcars2 <- mtcars")
121121
#' qq <- join(q1, q2)
122-
#' get_code(qq)
122+
#' cat(get_code(qq))
123123
#'
124124
#' common_q <- eval_code(q, quote(x <- 1))
125125
#' y_q <- eval_code(common_q, quote(y <- x * 2))
126126
#' z_q <- eval_code(common_q, quote(z <- x * 3))
127127
#' join_q <- join(y_q, z_q)
128128
#' # get_code only has "x <- 1" occurring once
129-
#' get_code(join_q)
129+
#' cat(get_code(join_q))
130130
#'
131131
#' @include qenv-errors.R
132132
#'

man/join.Rd

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

0 commit comments

Comments
 (0)