Skip to content

Add support for vctrs::vec_cast #266

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

Closed
colearendt opened this issue Apr 15, 2020 · 0 comments
Closed

Add support for vctrs::vec_cast #266

colearendt opened this issue Apr 15, 2020 · 0 comments
Labels
feature a feature request or enhancement

Comments

@colearendt
Copy link

In many cases, it would be helpful to have the ability to cast integers, etc. to fs_bytes. For instance:

library(experiment)

vctrs::vec_cast(as.integer(c(2L, 4L)), fs::as_fs_bytes(1L))
#> Warning: The `vec_cast.fs_bytes` function is experimental and subject to change without warning in a future release
#> This warning is displayed once per session.
#> 2 4

Created on 2020-04-15 by the reprex package (v0.3.0)

This required the following, and will require a Suggests dependency on vctrs:

#' @export
vec_cast.fs_bytes.integer <- function(x, to, ...) {
  warn_experimental("vec_cast.fs_bytes")
  fs::as_fs_bytes(x)
}

#' @export
vec_cast.fs_bytes.default <- function(x, to, ...) {
  vctrs::vec_default_cast(x = x, to = to)
}

#' @export
vec_cast.fs_bytes <- function(x, to, ...) {
  warn_experimental("vec_cast.fs_bytes")
  UseMethod("vec_cast.fs_bytes")
}


@jimhester jimhester added the feature a feature request or enhancement label Apr 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants