-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support for "AsIs" #906
Comments
If we don't want to propagate library(vctrs)
x <- I("asis")
vec_c(x)
#> Error: Can't find vctrs or base methods for concatenation.
#> vctrs methods must be implemented for class `AsIs`.
#> See <https://vctrs.r-lib.org/articles/s3-vector.html>.
strip_as_is <- function(x) {
class(x) <- setdiff(class(x), "AsIs")
x
}
vec_ptype2.AsIs <- function(x, y, ..., x_arg = "x", y_arg = "y") {
vec_ptype2(strip_as_is(x), y)
}
vec_ptype2.character.AsIs <- function(x, y, ..., x_arg = "x", y_arg = "y") {
vec_ptype2(x, strip_as_is(y))
}
vec_ptype2(x, x)
#> character(0)
vec_ptype2(x, "x")
#> character(0)
vec_ptype2("x", x)
#> character(0)
vec_cast.AsIs <- function(x, to, ...) {
vec_cast(x, strip_as_is(to))
}
vec_cast.character.AsIs <- function(x, to, ...) {
vec_cast(strip_as_is(x), to)
}
vec_cast(x, x)
#> [1] "asis"
class(vec_cast(x, x))
#> [1] "character"
vec_cast(x, "x")
#> [1] "asis"
vec_cast("x", x)
#> [1] "x"
vec_c(x,x)
#> [1] "asis" "asis"
class(vec_c(x,x))
#> [1] "character"
vec_c(x, "x")
#> [1] "asis" "x"
vec_c("x", x)
#> [1] "x" "asis" Created on 2020-03-11 by the reprex package (v0.3.0) |
Hmmm, this is going to require a little thought because AsIs behaves like a subclass of any existing class, which because we no longer rely on inheritance in vctrs is going to require an arbitrary and unknown number of methods. Should we add something in |
This breaks packages biotmle, FindMyFriends, incadata, radiant.multivariate, sitar on
dplyr
1.0.0 rev deps.Created on 2020-03-11 by the reprex package (v0.3.0)
The text was updated successfully, but these errors were encountered: