|
136 | 136 | setGeneric("join", function(x, y) standardGeneric("join")) |
137 | 137 |
|
138 | 138 | setMethod("join", signature = c("qenv", "qenv"), function(x, y) { |
139 | | - join_validation <- .check_joinable(x, y) |
140 | | - |
141 | | - # join expressions |
142 | | - if (!isTRUE(join_validation)) { |
143 | | - stop(join_validation) |
144 | | - } |
145 | | - |
146 | | - id_unique <- !y@id %in% x@id |
147 | | - x@id <- c(x@id, y@id[id_unique]) |
148 | | - x@code <- c(x@code, y@code[id_unique]) |
149 | | - x@warnings <- c(x@warnings, y@warnings[id_unique]) |
150 | | - x@messages <- c(x@messages, y@messages[id_unique]) |
151 | | - |
152 | | - # insert (and overwrite) objects from y to x |
153 | | - x@.xData <- rlang::env_clone(x@.xData, parent = parent.env(.GlobalEnv)) |
154 | | - rlang::env_coalesce(env = x@.xData, from = y@.xData) |
155 | | - x |
| 139 | + lifecycle::deprecate_soft("0.5.1", "join()", details = "Please use `c()` instead") |
| 140 | + c(x, y) |
156 | 141 | }) |
157 | 142 |
|
158 | 143 | setMethod("join", signature = c("qenv", "qenv.error"), function(x, y) { |
| 144 | + lifecycle::deprecate_soft("0.5.1", "join()", details = "Please use `c()` instead") |
159 | 145 | y |
160 | 146 | }) |
161 | 147 |
|
162 | 148 | setMethod("join", signature = c("qenv.error", "ANY"), function(x, y) { |
| 149 | + lifecycle::deprecate_soft("0.5.1", "join()", details = "Please use `c()` instead") |
163 | 150 | x |
164 | 151 | }) |
165 | 152 |
|
@@ -214,3 +201,45 @@ setMethod("join", signature = c("qenv.error", "ANY"), function(x, y) { |
214 | 201 | ) |
215 | 202 | } |
216 | 203 | } |
| 204 | + |
| 205 | +#' @export |
| 206 | +c.qenv.error <- function(...) { |
| 207 | + rlang::list2(...)[[1]] |
| 208 | +} |
| 209 | + |
| 210 | +#' @export |
| 211 | +c.qenv <- function(...) { |
| 212 | + dots <- rlang::list2(...) |
| 213 | + if (!checkmate::test_list(dots[-1], types = c("qenv", "qenv.error"))) { |
| 214 | + return(NextMethod(c, dots[[1]])) |
| 215 | + } |
| 216 | + |
| 217 | + first_non_qenv_ix <- which.min(vapply(dots, inherits, what = "qenv", logical(1))) |
| 218 | + if (first_non_qenv_ix > 1) { |
| 219 | + return(dots[[first_non_qenv_ix]]) |
| 220 | + } |
| 221 | + |
| 222 | + Reduce( |
| 223 | + x = dots[-1], |
| 224 | + init = dots[[1]], |
| 225 | + f = function(x, y) { |
| 226 | + join_validation <- .check_joinable(x, y) |
| 227 | + |
| 228 | + # join expressions |
| 229 | + if (!isTRUE(join_validation)) { |
| 230 | + stop(join_validation) |
| 231 | + } |
| 232 | + |
| 233 | + id_unique <- !y@id %in% x@id |
| 234 | + x@id <- c(x@id, y@id[id_unique]) |
| 235 | + x@code <- c(x@code, y@code[id_unique]) |
| 236 | + x@warnings <- c(x@warnings, y@warnings[id_unique]) |
| 237 | + x@messages <- c(x@messages, y@messages[id_unique]) |
| 238 | + |
| 239 | + # insert (and overwrite) objects from y to x |
| 240 | + x@.xData <- rlang::env_clone(x@.xData, parent = parent.env(.GlobalEnv)) |
| 241 | + rlang::env_coalesce(env = x@.xData, from = y@.xData) |
| 242 | + x |
| 243 | + } |
| 244 | + ) |
| 245 | +} |
0 commit comments