Skip to content

Commit

Permalink
Merge pull request #118 from mojaveazure/ah-remove-rgeos
Browse files Browse the repository at this point in the history
Remove `rgeos` from suggests and add `sf`
  • Loading branch information
AustinHartman authored Jul 21, 2023
2 parents dd6825e + 888d38b commit 200b59b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 27 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: SeuratObject
Type: Package
Title: Data Structures for Single Cell Data
Version: 4.1.3.9002
Date: 2023-03-08
Version: 4.1.3.9003
Date: 2023-07-21
Authors@R: c(
person(given = 'Rahul', family = 'Satija', email = 'rsatija@nygenome.org', role = 'aut', comment = c(ORCID = '0000-0001-9448-8833')),
person(given = 'Andrew', family = 'Butler', email = 'abutler@nygenome.org', role = 'aut', comment = c(ORCID = '0000-0003-3608-0463')),
Expand All @@ -29,7 +29,7 @@ BugReports:
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.1
RoxygenNote: 7.2.3
Depends:
R (>= 4.0.0),
sp (>= 1.5.0)
Expand All @@ -48,7 +48,7 @@ Imports:
utils
Suggests:
ggplot2,
rgeos,
sf,
testthat
Collate:
'RcppExports.R'
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Unreleased
## Changes
- Fixes for `CellsByIdentities` (#80)
- Remove {rgeos} from Suggests and replace with {sf} due to {rgeos} package retirement

# SeuratObject 4.1.3
## Changes
- Move {rgeos} to Suggests; segmentation simplification now requires {regos} to be installed manually
- Move {rgeos} to Suggests; segmentation simplification now requires {rgeos} to be installed manually
- Move {sp} to Depends

## Added
Expand Down
1 change: 0 additions & 1 deletion R/generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,6 @@ SetIdent <- function(object, ...) {

#' Simplify Geometry
#'
#' @inheritParams rgeos::gSimplify
#' @param coords ...
#'
#' @return ...
Expand Down
48 changes: 28 additions & 20 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -708,35 +708,43 @@ S4ToList.list <- function(object) {
return(object)
}

#' Simplify segmentations by reducing the number of vertices
#'
#' @param coords A `Segmentation` object
#' @param tol Numerical tolerance value to be used by the Douglas-Peuker algorithm
#' @param topologyPreserve Logical determining if the algorithm should attempt to preserve the topology of the original geometry
#'
#' @return A `Segmentation` object with simplified segmentation vertices
#'
#' @rdname Simplify
#' @method Simplify Spatial
#' @export
#'
Simplify.Spatial <- function(coords, tol, topologyPreserve = TRUE) {
if (!PackageCheck('rgeos', error = FALSE)) {
stop("'Simplify' requires rgeos to be installed", call. = FALSE)
if (!PackageCheck("sf", error = FALSE)) {
stop("'Simplify' requires sf to be installed", call. = FALSE)
}
class.orig <- class(x = coords)
coords.orig <- coords
dest <- ifelse(
test = grepl(pattern = '^Spatial', x = class.orig),
test = grepl(pattern = "^Spatial", x = class.orig),
yes = class.orig,
no = grep(
pattern = '^Spatial',
x = .Contains(object = coords),
value = TRUE
)[1L]
)
coords <- rgeos::gSimplify(
spgeom = as(object = coords, Class = dest),
tol = as.numeric(x = tol),
topologyPreserve = isTRUE(x = topologyPreserve)
)
coords <- tryCatch(
expr = as(object = coords, Class = class.orig),
error = function(...) {
return(coords)
}
)
no = grep(pattern = "^Spatial", x = .Contains(object = coords), value = TRUE)[1L])
x <- sf::st_as_sfc(as(object = coords, Class = dest))
coords <- sf::st_simplify(
x = x,
dTolerance = as.numeric(x = tol),
preserveTopology = isTRUE(x = topologyPreserve))
coords <- sf::st_sf(geometry = coords)
coords <- as(coords, Class = "Spatial")
coords <- as(coords, Class = "Segmentation")
slot(object = coords, name = "polygons") <- mapply(
FUN = function(x, y) {
slot(object = x, name = "ID") <- y
return(x)
},
slot(object = coords, name = "polygons"),
Cells(coords.orig))
return(coords)
}

Expand Down
6 changes: 5 additions & 1 deletion man/Simplify.Rd

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

0 comments on commit 200b59b

Please # to comment.