From a5ec0d0e77452fd5e85879b9caa27493255de090 Mon Sep 17 00:00:00 2001 From: Emi Tanaka Date: Sun, 15 Oct 2023 15:12:05 +1100 Subject: [PATCH] fix vctrs for edbl_rcrd --- NAMESPACE | 12 ++++++++++++ R/fcts.R | 41 ++++++++++++++++++++++++++--------------- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 7b0dac5..2f077bb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -37,11 +37,16 @@ S3method(tbl_sum,edbl_table) S3method(tbl_sum,trck_table) S3method(type_sum,edbl_fct) S3method(vec_cast,character.edbl_fct) +S3method(vec_cast,character.edbl_rcrd) S3method(vec_cast,character.edbl_trt) S3method(vec_cast,character.edbl_unit) +S3method(vec_cast,double.edbl_rcrd) S3method(vec_cast,double.edbl_trt) S3method(vec_cast,double.edbl_unit) S3method(vec_cast,edbl_fct.character) +S3method(vec_cast,edbl_rcrd.character) +S3method(vec_cast,edbl_rcrd.double) +S3method(vec_cast,edbl_rcrd.integer) S3method(vec_cast,edbl_trt.character) S3method(vec_cast,edbl_trt.double) S3method(vec_cast,edbl_trt.integer) @@ -49,6 +54,7 @@ S3method(vec_cast,edbl_unit.character) S3method(vec_cast,edbl_unit.double) S3method(vec_cast,edbl_unit.edbl_unit) S3method(vec_cast,edbl_unit.integer) +S3method(vec_cast,integer.edbl_rcrd) S3method(vec_cast,integer.edbl_trt) S3method(vec_cast,integer.edbl_unit) S3method(vec_math,edbl_fct) @@ -196,10 +202,16 @@ importFrom(vctrs,new_rcrd) importFrom(vctrs,new_vctr) importFrom(vctrs,vec_as_names) importFrom(vctrs,vec_cast) +importFrom(vctrs,vec_cast.character) +importFrom(vctrs,vec_cast.double) +importFrom(vctrs,vec_cast.integer) importFrom(vctrs,vec_data) importFrom(vctrs,vec_is) importFrom(vctrs,vec_math) importFrom(vctrs,vec_ptype2) +importFrom(vctrs,vec_ptype2.character) +importFrom(vctrs,vec_ptype2.double) +importFrom(vctrs,vec_ptype2.integer) importFrom(vctrs,vec_ptype_abbr) importFrom(vctrs,vec_ptype_full) importFrom(vctrs,vec_size_common) diff --git a/R/fcts.R b/R/fcts.R index 91d6699..1e02f6a 100644 --- a/R/fcts.R +++ b/R/fcts.R @@ -155,7 +155,7 @@ vec_math.edbl_fct <- function(.fn, .x, ...) { get(.fn)(unclass(.x)) } -#' @importFrom vctrs vec_ptype2 +#' @importFrom vctrs vec_ptype2 vec_ptype2.double vec_ptype2.integer vec_ptype2.character #' @export vec_ptype2.edbl_unit.character <- function(x, y, ...) y #' @export @@ -195,34 +195,45 @@ vec_ptype2.edbl_rcrd.integer <- function(x, y, ...) y #' @export vec_ptype2.integer.edbl_rcrd <- function(x, y, ...) x -#' @importFrom vctrs vec_cast +#' @importFrom vctrs vec_cast vec_cast.double vec_cast.integer vec_cast.character #' @export -vec_cast.edbl_trt.double <- function(x, to, ...) to +vec_cast.edbl_trt.double <- function(x, to, ...) x #' @export -vec_cast.double.edbl_trt <- function(x, to, ...) x +vec_cast.double.edbl_trt <- function(x, to, ...) as.numeric(unclass(x)) #' @export -vec_cast.edbl_trt.integer <- function(x, to, ...) to +vec_cast.edbl_trt.integer <- function(x, to, ...) x #' @export -vec_cast.integer.edbl_trt <- function(x, to, ...) x +vec_cast.integer.edbl_trt <- function(x, to, ...) as.integer(unclass(x)) #' @export -vec_cast.edbl_trt.character <- function(x, to, ...) to +vec_cast.edbl_trt.character <- function(x, to, ...) x #' @export -vec_cast.character.edbl_trt <- function(x, to, ...) x +vec_cast.character.edbl_trt <- function(x, to, ...) as.character(unclass(x)) #' @export -vec_cast.edbl_unit.double <- function(x, to, ...) to +vec_cast.edbl_unit.double <- function(x, to, ...) x #' @export -vec_cast.double.edbl_unit <- function(x, to, ...) x +vec_cast.double.edbl_unit <- function(x, to, ...) as.numeric(unclass(x)) #' @export -vec_cast.edbl_unit.integer <- function(x, to, ...) to +vec_cast.edbl_unit.integer <- function(x, to, ...) x #' @export -vec_cast.integer.edbl_unit <- function(x, to, ...) x +vec_cast.integer.edbl_unit <- function(x, to, ...) as.integer(unclass(x)) #' @export -vec_cast.edbl_unit.character <- function(x, to, ...) to +vec_cast.edbl_unit.character <- function(x, to, ...) x #' @export -vec_cast.character.edbl_unit <- function(x, to, ...) x - +vec_cast.character.edbl_unit <- function(x, to, ...) as.character(unclass(x)) +#' @export +vec_cast.edbl_rcrd.double <- function(x, to, ...) x +#' @export +vec_cast.double.edbl_rcrd <- function(x, to, ...) as.numeric(unclass(x)) +#' @export +vec_cast.edbl_rcrd.integer <- function(x, to, ...) x +#' @export +vec_cast.integer.edbl_rcrd <- function(x, to, ...) as.integer(unclass(x)) +#' @export +vec_cast.edbl_rcrd.character <- function(x, to, ...) x +#' @export +vec_cast.character.edbl_rcrd <- function(x, to, ...) as.character(unclass(x)) # ADDME add_units(exist = TRUE), reset_units(exist = FALSE)