|
1 | 1 | #' Join `qenv` objects |
2 | 2 | #' |
3 | 3 | #' @description |
4 | | -#' Checks and merges two `qenv` objects into one `qenv` object. |
| 4 | +#' `r lifecycle::badge("deprecated")` |
| 5 | +#' Instead of [join()] use [c()]. |
5 | 6 | #' |
6 | | -#' The `join()` function is superseded by the `c()` function. |
7 | | -#' |
8 | | -#' @details |
9 | | -#' Any common code at the start of the `qenvs` is only placed once at the start of the joined `qenv`. |
10 | | -#' This allows consistent behavior when joining `qenvs` which share a common ancestor. |
11 | | -#' See below for an example. |
12 | | -#' |
13 | | -#' There are some situations where `join()` cannot be properly performed, such as these three scenarios: |
14 | | -#' 1. Both `qenv` objects contain an object of the same name but are not identical. |
15 | | -#' |
16 | | -#' Example: |
17 | | -#' |
18 | | -#' ```r |
19 | | -#' x <- eval_code(qenv(), expression(mtcars1 <- mtcars)) |
20 | | -#' y <- eval_code(qenv(), expression(mtcars1 <- mtcars['wt'])) |
21 | | -#' |
22 | | -#' z <- c(x, y) |
23 | | -#' # Error message will occur |
24 | | -#' ``` |
25 | | -#' In this example, `mtcars1` object exists in both `x` and `y` objects but the content are not identical. |
26 | | -#' `mtcars1` in the `x qenv` object has more columns than `mtcars1` in the `y qenv` object (only has one column). |
27 | | -#' |
28 | | -#' 2. `join()` will look for identical code elements in both `qenv` objects. |
29 | | -#' The index position of these code elements must be the same to determine the evaluation order. |
30 | | -#' Otherwise, `join()` will throw an error message. |
31 | | -#' |
32 | | -#' Example: |
33 | | -#' ```r |
34 | | -#' common_q <- eval_code(qenv(), expression(v <- 1)) |
35 | | -#' x <- eval_code( |
36 | | -#' common_q, |
37 | | -#' "x <- v" |
38 | | -#' ) |
39 | | -#' y <- eval_code( |
40 | | -#' common_q, |
41 | | -#' "y <- v" |
42 | | -#' ) |
43 | | -#' z <- eval_code( |
44 | | -#' y, |
45 | | -#' "z <- v" |
46 | | -#' ) |
47 | | -#' q <- c(x, y) |
48 | | -#' join_q <- c(q, z) |
49 | | -#' # Error message will occur |
50 | | -#' |
51 | | -#' # Check the order of evaluation based on the id slot |
52 | | -#' ``` |
53 | | -#' The error occurs because the index position of common code elements in the two objects is not the same. |
54 | | -#' |
55 | | -#' 3. The usage of temporary variable in the code expression could cause `join()` to fail. |
56 | | -#' |
57 | | -#' Example: |
58 | | -#' ```r |
59 | | -#' common_q <- qenv() |
60 | | -#' x <- eval_code( |
61 | | -#' common_q, |
62 | | -#' "x <- numeric(0) |
63 | | -#' for (i in 1:2) { |
64 | | -#' x <- c(x, i) |
65 | | -#' }" |
66 | | -#' ) |
67 | | -#' y <- eval_code( |
68 | | -#' common_q, |
69 | | -#' "y <- numeric(0) |
70 | | -#' for (i in 1:3) { |
71 | | -#' y <- c(y, i) |
72 | | -#' }" |
73 | | -#' ) |
74 | | -#' q <- join(x,y) |
75 | | -#' # Error message will occur |
76 | | -#' |
77 | | -#' # Check the value of temporary variable i in both objects |
78 | | -#' x$i # Output: 2 |
79 | | -#' y$i # Output: 3 |
80 | | -#' ``` |
81 | | -#' `c()` fails to provide a proper result because of the temporary variable `i` exists |
82 | | -#' in both objects but has different value. |
83 | | -#' To fix this, we can set `i <- NULL` in the code expression for both objects. |
84 | | -#' ```r |
85 | | -#' common_q <- qenv() |
86 | | -#' x <- eval_code( |
87 | | -#' common_q, |
88 | | -#' "x <- numeric(0) |
89 | | -#' for (i in 1:2) { |
90 | | -#' x <- c(x, i) |
91 | | -#' } |
92 | | -#' # dummy i variable to fix it |
93 | | -#' i <- NULL" |
94 | | -#' ) |
95 | | -#' y <- eval_code( |
96 | | -#' common_q, |
97 | | -#' "y <- numeric(0) |
98 | | -#' for (i in 1:3) { |
99 | | -#' y <- c(y, i) |
100 | | -#' } |
101 | | -#' # dummy i variable to fix it |
102 | | -#' i <- NULL" |
103 | | -#' ) |
104 | | -#' q <- c(x,y) |
105 | | -#' ``` |
106 | | -#' |
107 | | -#' @param x (`qenv`) |
108 | | -#' @param y (`qenv`) |
109 | | -#' |
110 | | -#' @return `qenv` object. |
111 | | -#' |
112 | | -#' @examples |
113 | | -#' q <- qenv() |
114 | | -#' q1 <- eval_code(q, expression(iris1 <- iris, mtcars1 <- mtcars)) |
115 | | -#' q2 <- q1 |
116 | | -#' q1 <- eval_code(q1, "iris2 <- iris") |
117 | | -#' q2 <- eval_code(q2, "mtcars2 <- mtcars") |
118 | | -#' qq <- join(q1, q2) |
119 | | -#' cat(get_code(qq)) |
120 | | -#' |
121 | | -#' common_q <- eval_code(q, quote(x <- 1)) |
122 | | -#' y_q <- eval_code(common_q, quote(y <- x * 2)) |
123 | | -#' z_q <- eval_code(common_q, quote(z <- x * 3)) |
124 | | -#' join_q <- join(y_q, z_q) |
125 | | -#' # get_code only has "x <- 1" occurring once |
126 | | -#' cat(get_code(join_q)) |
127 | | -#' |
128 | | -#' @include qenv-errors.R |
| 7 | +#' @param ... function is deprecated. |
129 | 8 | #' |
130 | 9 | #' @name join |
131 | 10 | #' @rdname join |
132 | | -#' @aliases join,qenv,qenv-method |
133 | | -#' @aliases join,qenv,qenv.error-method |
134 | | -#' @aliases join,qenv.error,ANY-method |
135 | 11 | #' |
136 | 12 | #' @export |
137 | | -setGeneric("join", function(x, y) standardGeneric("join")) |
138 | | - |
139 | | -setMethod("join", signature = c("qenv", "qenv"), function(x, y) { |
140 | | - lifecycle::deprecate_soft("0.6.0", "join()", "c()") |
141 | | - c(x, y) |
142 | | -}) |
143 | | - |
144 | | -setMethod("join", signature = c("qenv", "qenv.error"), function(x, y) { |
145 | | - lifecycle::deprecate_soft("0.6.0", "join()", "c()") |
146 | | - y |
147 | | -}) |
148 | | - |
149 | | -setMethod("join", signature = c("qenv.error", "ANY"), function(x, y) { |
150 | | - lifecycle::deprecate_soft("0.6.0", "join()", "c()") |
151 | | - x |
152 | | -}) |
| 13 | +join <- function(...) lifecycle::deprecate_stop("0.6.0", "join()", "c()") |
0 commit comments