Skip to content

Commit

Permalink
Fix registration and exporting of double-dispatch methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed Nov 19, 2019
1 parent 87612f0 commit 5e1562c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 18 deletions.
4 changes: 3 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ S3method(summary,sfc)
S3method(t,sgbp)
S3method(vec_cast.sfc,default)
S3method(vec_cast.sfc,sfc)
S3method(vec_ptype2.sfc,default)
S3method(vec_ptype2.sfc,sfc)
export("%>%")
export("st_agr<-")
export("st_crs<-")
Expand Down Expand Up @@ -382,7 +384,7 @@ export(st_write)
export(st_write_db)
export(st_zm)
export(vec_cast.sfc)
export(vec_proxy.sfc)
export(vec_ptype2.sfc)
export(write_sf)
exportMethods(dbDataType)
exportMethods(dbWriteTable)
Expand Down
18 changes: 12 additions & 6 deletions R/tidyverse.R
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,20 @@ vec_restore.sfc <- function(x, to, ...) {
ret
}

#' vctrs methods for sf objects
#' @name vctrs
#' @export
#' @inheritParams vctrs::vec_ptype2
vec_ptype2.sfc <- function(x, y, ...) {
UseMethod("vec_ptype2.sfc", y)
}
#' @name vctrs
#' @export
vec_ptype2.sfc.default <- function(x, y, ..., x_arg = "x", y_arg = "y") {
vctrs::vec_default_ptype2(x, y, x_arg = x_arg, y_arg = y_arg)
}
#' @name vctrs
#' @export
vec_ptype2.sfc.sfc <- function(x, y, ...) {
ucls = unique(c(class(x)[1], class(y)[1]))
cls =
Expand All @@ -412,18 +420,18 @@ vec_ptype2.sfc.sfc <- function(x, y, ...) {


# minimal vec_cast implementation: https://github.com/r-spatial/sf/issues/1068
#' @name tidyverse
#' @name vctrs
#' @export
#' @param to character; target class
#' @inheritParams vctrs::vec_cast
vec_cast.sfc <- function(x, to, ...) UseMethod("vec_cast.sfc") # nocov

#' @name tidyverse
#' @name vctrs
#' @export
vec_cast.sfc.sfc <- function(x, to, ...) {
st_cast(x, gsub("sfc_", "", class(to)[1])) # nocov
}

#' @name tidyverse
#' @name vctrs
#' @export
vec_cast.sfc.default <- function(x, to, ...) {
if (!requireNamespace("vctrs", quietly = TRUE)) # nocov start
Expand Down Expand Up @@ -466,8 +474,6 @@ register_all_s3_methods = function() {
register_s3_method("vctrs", "vec_proxy", "sfc")
register_s3_method("vctrs", "vec_restore", "sfc")
register_s3_method("vctrs", "vec_ptype2", "sfc")
register_s3_method("vctrs", "vec_ptype2.sfc", "default")
register_s3_method("vctrs", "vec_ptype2.sfc", "sfc")
}

# from: https://github.com/tidyverse/hms/blob/master/R/zzz.R
Expand Down
11 changes: 0 additions & 11 deletions man/tidyverse.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions man/vctrs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5e1562c

Please sign in to comment.