Skip to content

Commit 91109f7

Browse files
committed
fixes #1472
1 parent d37a225 commit 91109f7

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# version 1.0-13
22

3+
* add `rename_with.sf()` method; #1472
4+
35
* use GEOS' overlayNG routines for (GEOS) Intersection, Difference, Union and SymDifference; #2143
46

57
* added `duplicated.sf()`; #2138, #2140, thanks to @bart1

R/tidyverse.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,18 @@ rename.sf <- function(.data, ...) {
235235
st_set_agr(st_as_sf(ret, sf_column_name = sf_column), agr)
236236
}
237237

238+
rename_with.sf = function(.data, .fn, .cols = everything(), ...) {
239+
if (!requireNamespace("rlang", quietly = TRUE))
240+
stop("rlang required: install that first") # nocov
241+
.fn = rlang::as_function(.fn)
242+
agr = st_agr(.data)
243+
ret = NextMethod()
244+
names(agr) = .fn(names(agr))
245+
st_agr(ret) = agr
246+
ret
247+
}
248+
249+
238250
#' @name tidyverse
239251
#' @examples
240252
#' if (require(dplyr, quietly = TRUE)) {
@@ -632,6 +644,7 @@ register_all_s3_methods = function() {
632644
register_s3_method("dplyr", "left_join", "sf")
633645
register_s3_method("dplyr", "mutate", "sf")
634646
register_s3_method("dplyr", "rename", "sf")
647+
register_s3_method("dplyr", "rename_with", "sf")
635648
register_s3_method("dplyr", "right_join", "sf")
636649
register_s3_method("dplyr", "rowwise", "sf")
637650
register_s3_method("dplyr", "sample_frac", "sf")

0 commit comments

Comments
 (0)