diff --git a/R/tidyverse.R b/R/tidyverse.R index 59a28313e..0a59145f9 100644 --- a/R/tidyverse.R +++ b/R/tidyverse.R @@ -1,4 +1,4 @@ -## dplyr methods: +## dplyr methods: ------ #group_map.sf <- function(.tbl, .f, ...) { # st_as_sf(NextMethod()) # nocov #} @@ -375,7 +375,7 @@ distinct.sf <- function(.data, ..., .keep_all = FALSE) { } } -## tidyr methods: +## tidyr methods: -------- #' @name tidyverse #' @param data see original function docs @@ -404,20 +404,11 @@ gather.sf <- function(data, key, value, ..., na.rm = FALSE, convert = FALSE, fac sf_column_name = attr(data, "sf_column")) } -#' @name tidyverse +#' @rdname tidyverse #' @param data see original function docs #' @param cols see original function docs -#' @param names_to see original function docs -#' @param names_prefix see original function docs -#' @param names_sep see original function docs -#' @param names_pattern see original function docs -#' @param names_ptypes see original function docs -#' @param names_transform see original function docs -#' @param names_repair see original function docs -#' @param values_to see original function docs -#' @param values_drop_na see original function docs -#' @param values_ptypes see original function docs -#' @param values_transform see original function docs +#' @param names_to,names_prefix,names_sep,names_pattern,names_ptype,names_transform,names_repair see [tidyr::pivot_longer()] +#' @param values_to,values_drop_na,value_ptypes,values_transform See [tidyr::pivot_longer()] pivot_longer.sf <- function (data, cols, names_to = "name", names_prefix = NULL, names_sep = NULL, names_pattern = NULL, names_ptypes = NULL, names_transform = NULL, names_repair = "check_unique", @@ -452,23 +443,12 @@ pivot_longer.sf <- function (data, cols, names_to = "name", names_prefix = NULL, st_as_sf(out, sf_column_name = sf_column_name) } -globalVariables(c("name", "value")) +utils::globalVariables(c("name", "value")) # https://github.com/r-spatial/sf/issues/1915 -#' @name tidyverse -#' @export -#' @param id_cols see original function docs -#' @param id_expand see original function docs -#' @param names_from see original function docs -#' @param names_prefix see original function docs -#' @param names_sep see original function docs -#' @param names_glue see original function docs -#' @param names_sort see original function docs -#' @param names_vary see original function docs -#' @param names_expand see original function docs -#' @param names_repair see original function docs -#' @param values_from see original function docs -#' @param values_fill see original function docs -#' @param values_fn see original function docs +#' @rdname tidyverse +#' @param id_cols,id_expand see [tidyr::pivot_wider()] +#' @param names_from,names_prefix,names_sep,names_glue,names_sort,names_wary,names_repair see [tidyr::pivot_wider()]. +#' @param values_from,values_fill,values_fn see [tidyr::pivot_wider()] #' @param unused_fn see original function docs pivot_wider.sf = function(data, ..., @@ -644,12 +624,19 @@ unnest.sf = function(data, ..., .preserve = NULL) { # nocov end } -## tibble methods: +#' @name tidyverse +drop_na.sf <- function(x, ...) { + sf_column_name = attr(x, "sf_column") + class(x) <- setdiff(class(x), "sf") + st_as_sf(NextMethod(), sf_column_name = sf_column_name) +} + +## tibble methods: ------- #' Summarize simple feature type for tibble #' -#' Summarize simple feature type for tibble -#' @param x object of class sfc +#' Summarize simple feature type / item for tibble +#' @param x object of class `sfc` #' @param ... ignored #' @name tibble #' @details see \link[pillar]{type_sum} @@ -661,15 +648,12 @@ type_sum.sfc <- function(x, ...) { cls } -#' Summarize simple feature item for tibble -#' -#' Summarize simple feature item for tibble -#' @name tibble +#' @rdname tibble obj_sum.sfc <- function(x) { vapply(x, function(sfg) format(sfg, width = 15L), "") } -#' @name tibble +#' @rdname tibble pillar_shaft.sfc <- function(x, ...) { digits = options("pillar.sigfig")$pillar.sigfig if (is.null(digits)) @@ -680,13 +664,6 @@ pillar_shaft.sfc <- function(x, ...) { pillar::new_pillar_shaft_simple(out, align = "right", min_width = 25) } -#' @name tidyverse -drop_na.sf <- function(x, ...) { - sf_column_name = attr(x, "sf_column") - class(x) <- setdiff(class(x), "sf") - st_as_sf(NextMethod(), sf_column_name = sf_column_name) -} - #nocov start register_all_s3_methods = function() { has_dplyr_1.0 = diff --git a/man/tibble.Rd b/man/tibble.Rd index ee92cd22e..5f0c1bb05 100644 --- a/man/tibble.Rd +++ b/man/tibble.Rd @@ -14,14 +14,12 @@ obj_sum.sfc(x) pillar_shaft.sfc(x, ...) } \arguments{ -\item{x}{object of class sfc} +\item{x}{object of class \code{sfc}} \item{...}{ignored} } \description{ -Summarize simple feature type for tibble - -Summarize simple feature item for tibble +Summarize simple feature type / item for tibble } \details{ see \link[pillar]{type_sum} diff --git a/man/tidyverse.Rd b/man/tidyverse.Rd index 5a1ee0be7..e42a0849c 100644 --- a/man/tidyverse.Rd +++ b/man/tidyverse.Rd @@ -35,7 +35,7 @@ \alias{full_join.sf} \alias{semi_join.sf} \alias{anti_join.sf} -\title{Tidyverse methods for sf objects (remove .sf suffix!)} +\title{Tidyverse methods for sf objects} \usage{ filter.sf(.data, ..., .dots) @@ -200,47 +200,15 @@ more details.} \item{cols}{see original function docs} -\item{names_to}{see original function docs} +\item{names_to, names_prefix, names_sep, names_pattern, names_ptype, names_transform, names_repair}{see \code{\link[tidyr:pivot_longer]{tidyr::pivot_longer()}}} -\item{names_prefix}{see original function docs} +\item{values_to, values_drop_na, value_ptypes, values_transform}{See \code{\link[tidyr:pivot_longer]{tidyr::pivot_longer()}}} -\item{names_sep}{see original function docs} +\item{id_cols, id_expand}{see \code{\link[tidyr:pivot_wider]{tidyr::pivot_wider()}}} -\item{names_pattern}{see original function docs} +\item{names_from, names_prefix, names_sep, names_glue, names_sort, names_wary, names_repair}{see \code{\link[tidyr:pivot_wider]{tidyr::pivot_wider()}}.} -\item{names_ptypes}{see original function docs} - -\item{names_transform}{see original function docs} - -\item{names_repair}{see original function docs} - -\item{values_to}{see original function docs} - -\item{values_drop_na}{see original function docs} - -\item{values_ptypes}{see original function docs} - -\item{values_transform}{see original function docs} - -\item{id_cols}{see original function docs} - -\item{id_expand}{see original function docs} - -\item{names_from}{see original function docs} - -\item{names_glue}{see original function docs} - -\item{names_sort}{see original function docs} - -\item{names_vary}{see original function docs} - -\item{names_expand}{see original function docs} - -\item{values_from}{see original function docs} - -\item{values_fill}{see original function docs} - -\item{values_fn}{see original function docs} +\item{values_from, values_fill, values_fn}{see \code{\link[tidyr:pivot_wider]{tidyr::pivot_wider()}}} \item{unused_fn}{see original function docs} @@ -316,7 +284,8 @@ Should be a character vector of length 2.} an object of class \link{sf} } \description{ -Tidyverse methods for sf objects. Geometries are sticky, use \link{as.data.frame} to let \code{dplyr}'s own methods drop them. Use these methods without the .sf suffix and after loading the tidyverse package with the generic (or after loading package tidyverse). +Tidyverse methods for sf objects. Geometries are sticky, use \link{as.data.frame} to let \code{dplyr}'s own methods drop them. +Use these methods after loading the tidyverse package with the generic (or after loading package tidyverse). } \details{ \code{select} keeps the geometry regardless whether it is selected or not; to deselect it, first pipe through \code{as.data.frame} to let dplyr's own \code{select} drop it.