diff --git a/DESCRIPTION b/DESCRIPTION index 679bfed..0c79147 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -17,14 +17,17 @@ Depends: methods, graph Imports: - fields, - RBGL, - sp + fields, + RBGL, + rnaturalearth, + rnaturalearthdata, + sp, + sf, + magrittr Suggests: testthat, knitr, - rmarkdown, - sf + rmarkdown RoxygenNote: 7.2.3 Collate: 'classes.R' @@ -49,5 +52,6 @@ Collate: 'rebuild.R' 'setCosts.R' 'setDistCosts.R' + 'utils-pipe.R' 'zoom.R' 'zzz.R' diff --git a/NAMESPACE b/NAMESPACE index cdba679..ca52fd4 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,7 @@ # Generated by roxygen2: do not edit by hand S3method(plot,gPath) +export("%>%") export() export(.gData.valid) export(.gGraph.valid) @@ -77,3 +78,4 @@ import(sp) importFrom(graphics,identify) importFrom(graphics,locator) importFrom(graphics,segments) +importFrom(magrittr,"%>%") diff --git a/R/extractFromLayer.R b/R/extractFromLayer.R index 06d45ab..5f0b6a3 100644 --- a/R/extractFromLayer.R +++ b/R/extractFromLayer.R @@ -84,7 +84,7 @@ setGeneric("extractFromLayer", function(x, ...) { #' @rdname extractFromLayer #' @export setMethod("extractFromLayer", "matrix", function(x, layer = "world", attr = "all", ...) { - sf::sf_use_s2(FALSE) + ## This functions automatically assigns to land all points overlapping the country polygons # if(!require(maptools)) stop("maptools package is required.") @@ -93,13 +93,18 @@ setMethod("extractFromLayer", "matrix", function(x, layer = "world", attr = "all if (is.character(layer) && layer[1] == "world") { # use rnaturalearth instead of the inbuilt dataset # layer <- rnaturalearth::ne_countries(scale="medium", returnclass = "sf") + # sf::sf_use_s2(FALSE) layer <- sf::st_read(system.file("files/shapefiles/world-countries.shp", package = "geoGraph")) } ## TODO if the layer is null, we should throw an error!!! if (!is.null(layer)) { if (!inherits(layer, "sf")) { - stop("Layer must be a sf object \n(see st_read in sf to import such data from a GIS shapefile).") + if (inherits(layer, "SpatialPolygonsDataFrame")){ + layer <- sf::st_as_sf(layer) + } else { + stop("Layer must be a sf object \n(see st_read in sf to import such data from a GIS shapefile).") + } } } diff --git a/R/utils-pipe.R b/R/utils-pipe.R new file mode 100644 index 0000000..fd0b1d1 --- /dev/null +++ b/R/utils-pipe.R @@ -0,0 +1,14 @@ +#' Pipe operator +#' +#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. +#' +#' @name %>% +#' @rdname pipe +#' @keywords internal +#' @export +#' @importFrom magrittr %>% +#' @usage lhs \%>\% rhs +#' @param lhs A value or the magrittr placeholder. +#' @param rhs A function call using the magrittr semantics. +#' @return The result of calling `rhs(lhs)`. +NULL diff --git a/man/extractFromLayer.Rd b/man/extractFromLayer.Rd index 7eb940b..c92db67 100644 --- a/man/extractFromLayer.Rd +++ b/man/extractFromLayer.Rd @@ -71,15 +71,9 @@ input formats. plot(worldgraph.10k, reset = TRUE) - -## see what info is available -names(worldshape@data) -unique(worldshape@data$CONTINENT) - - ## retrieve continent info for all nodes ## (might take a few seconds) -x <- extractFromLayer(worldgraph.10k, layer = worldshape, attr = "CONTINENT") +x <- extractFromLayer(worldgraph.10k, layer = "world", attr = "CONTINENT") x table(getNodesAttr(x, attr.name = "CONTINENT")) diff --git a/man/pipe.Rd b/man/pipe.Rd new file mode 100644 index 0000000..a648c29 --- /dev/null +++ b/man/pipe.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils-pipe.R +\name{\%>\%} +\alias{\%>\%} +\title{Pipe operator} +\usage{ +lhs \%>\% rhs +} +\arguments{ +\item{lhs}{A value or the magrittr placeholder.} + +\item{rhs}{A function call using the magrittr semantics.} +} +\value{ +The result of calling \code{rhs(lhs)}. +} +\description{ +See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. +} +\keyword{internal} diff --git a/man/setCosts.Rd b/man/setCosts.Rd index 2398bac..f51dfbf 100644 --- a/man/setCosts.Rd +++ b/man/setCosts.Rd @@ -68,7 +68,6 @@ x <- setCosts(x, attr.name = "habitat") plot(x, edges = TRUE) title("costs defined by habitat (land/land=1, other=100)") - } \seealso{ \code{\link{dropDeadEdges}}, to get rid of edge whose cost is below