Skip to content

Commit cde88c3

Browse files
committed
Merge branch 'main' into fielddomain
2 parents 362d63f + 4031680 commit cde88c3

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ S3method(c,sfc)
2929
S3method(c,sfg)
3030
S3method(cbind,sf)
3131
S3method(dim,sgbp)
32+
S3method(duplicated,sf)
3233
S3method(format,bbox)
3334
S3method(format,crs)
3435
S3method(format,sfc)

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+
* added `duplicated.sf()`; #2138, #2140, thanks to @bart1
4+
35
* `select.sf()` allows selecting the same column twice under different names; #1886
46

57
* `st_as_sf.ppplist()` is deprecated; #1926

R/sf.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,23 @@ as.data.frame.sf = function(x, ...) {
450450
NextMethod()
451451
}
452452

453+
#' @export
454+
duplicated.sf <- function(x, incomparables = FALSE, fromLast = FALSE, ...) {
455+
if (length(x) != 1L) {
456+
if (any(i <- vapply(x, is.factor, NA))) {
457+
for (j in names(i[i])) {
458+
x[[j]] <- lapply(x[[j]], as.numeric)
459+
}
460+
}
461+
if (any(i <- (lengths(lapply(x, dim)) == 2L))) {
462+
for (j in names(i[i])) {
463+
x[[j]] <- lapply(x[[j]], split.data.frame, seq_len(nrow(x)))
464+
}
465+
}
466+
}
467+
NextMethod()
468+
}
469+
453470
#' @export
454471
#' @name st_geometry
455472
#' @details if \code{x} is of class \code{sf}, \code{st_drop_geometry} drops the geometry of its argument, and reclasses it accordingly; otherwise it returns \code{x} unmodified.

_pkgdown.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
url: https://r-spatial.github.io/sf/
2+
13
template:
24
bootstrap: 5

tests/testthat/test_sf.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,8 @@ test_that("empty agr attribute is named after subset", {
9999
agr = attr(out, "agr")
100100
expect_identical(names(agr), character())
101101
})
102+
test_that("duplicated work",{
103+
sf = st_sf(data.frame(x = st_sfc(st_point(1:2))[rep(1,4)], a=gl(2,2), b=as.numeric(gl(2,2))))
104+
expect_identical(duplicated(sf), c(FALSE,TRUE,FALSE,TRUE))
105+
expect_s3_class(unique(sf),'sf')
106+
})

0 commit comments

Comments
 (0)