Skip to content

Commit

Permalink
Added cast methods for csl types
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelloharawild committed Nov 6, 2020
1 parent f3e4ddb commit 46a46ce
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ export(slice)
export(summarise)
export(transmute)
export(twentyseconds)
export(vec_cast.character.csl_date)
export(vec_cast.character.csl_name)
export(vec_cast.double.csl_date)
export(vec_ptype2.csl_date.double)
export(vec_ptype2.double.csl_date)
import(glue)
importFrom(dplyr,"%>%")
importFrom(dplyr,arrange)
Expand Down
23 changes: 22 additions & 1 deletion R/csl_types.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ format.csl_name <- function(x, ...) {
#' @export
vec_ptype_abbr.csl_name <- function(x) "csl name"

#' @export
vec_cast.character.csl_name <- function(x, to, ...) {
format(x)
}

#' @export
xtfrm.csl_name <- function(x) {
xtfrm(format(x))
Expand Down Expand Up @@ -89,9 +94,25 @@ format.csl_date <- function(x, ...) {
vec_ptype_abbr.csl_date <- function(x) "csl_date"

#' @export
xtfrm.csl_date <- function(x) {
vec_ptype2.csl_date.double <- function(x, y, ...) {
double()
}
#' @export
vec_ptype2.double.csl_date <- vec_ptype2.csl_date.double

#' @export
vec_cast.double.csl_date <- function(x, to, ...) {
vapply(x, function(x) if(is.null(x)) NA_real_ else x[[1]][[1]], numeric(1L))
}
#' @export
vec_cast.character.csl_date <- function(x, to, ...) {
format(x)
}

#' @export
xtfrm.csl_date <- function(x) {
as.numeric(x)
}

#' @importFrom vctrs vec_proxy_order
#' @method vec_proxy_order csl_date
Expand Down

0 comments on commit 46a46ce

Please sign in to comment.