Skip to content

Commit

Permalink
some casting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mjskay committed Dec 23, 2023
1 parent 2146d06 commit 64920a2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,21 @@ S3method(vec_cast,character.mapped_discrete)
S3method(vec_cast,double.ggunit)
S3method(vec_cast,double.mapped_discrete)
S3method(vec_cast,factor.mapped_discrete)
S3method(vec_cast,ggunit.character)
S3method(vec_cast,ggunit.double)
S3method(vec_cast,ggunit.ggunit)
S3method(vec_cast,ggunit.integer)
S3method(vec_cast,ggunit.list)
S3method(vec_cast,ggunit.logical)
S3method(vec_cast,ggunit.mapped_discrete)
S3method(vec_cast,ggunit.simpleUnit)
S3method(vec_cast,ggunit.unit)
S3method(vec_cast,integer.ggunit)
S3method(vec_cast,integer.mapped_discrete)
S3method(vec_cast,logical.ggunit)
S3method(vec_cast,mapped_discrete.double)
S3method(vec_cast,mapped_discrete.factor)
S3method(vec_cast,mapped_discrete.ggunit)
S3method(vec_cast,mapped_discrete.integer)
S3method(vec_cast,mapped_discrete.logical)
S3method(vec_cast,mapped_discrete.mapped_discrete)
Expand Down
10 changes: 8 additions & 2 deletions R/ggunit.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ Ops.ggunit <- function(x, y) {

#' @export
chooseOpsMethod.ggunit = function(x, y, mx, my, cl, reverse) {
# TODO: something more comprehensive using vec_ptype2
inherits(x, "ggunit")
# TODO: something more comprehensive?
is_ggunit(vec_ptype2(x, y)) == is_ggunit(x)
}

#' @export
Expand Down Expand Up @@ -279,6 +279,12 @@ vec_cast.ggunit.logical <- function(x, to, ...) ggunit(x)
#' @export
vec_cast.logical.ggunit <- function(x, to, ...) as.logical(as.numeric(x))
#' @export
vec_cast.ggunit.mapped_discrete <- function(x, to, ...) ggunit(x)
#' @export
vec_cast.mapped_discrete.ggunit <- function(x, to, ...) new_mapped_discrete(as.numeric(x))
#' @export
vec_cast.ggunit.character <- function(x, to, ...) stop_incompatible_cast(x, to, x_arg = "a", to_arg = "to")
#' @export
vec_cast.ggunit.list <- function(x, to, ...) {
is_na <- vapply(x, is.null, logical(1))
x[is_na] <- NA
Expand Down

0 comments on commit 64920a2

Please sign in to comment.