Commit f518e2af authored by Facundo Muñoz's avatar Facundo Muñoz ®️
Browse files

documentation and namespace fixes

parent 206b2a95
......@@ -39,7 +39,6 @@ Imports:
stringr
Suggests:
devtools,
igraph,
knitr,
mapview,
rmarkdown,
......
# Generated by roxygen2: do not edit by hand
S3method(epidemic_threshold,data.frame)
S3method(epidemic_threshold,igraph)
export(align_layers)
export(borders0)
export(compute_weights)
export(distance_map)
export(distance_to_vector)
export(download_country_admin)
export(epidemic_threshold)
export(layer_type)
export(load_dir)
export(load_layer)
......@@ -17,6 +20,7 @@ export(risk_layer)
export(risk_plot)
export(risk_unit)
export(rmext)
export(voronoi)
export(wlc)
exportMethods(rasterize)
import(deldir)
......@@ -36,3 +40,6 @@ importFrom(igraph,graph_from_data_frame)
importFrom(igraph,is.weighted)
importFrom(raster,intersect)
importFrom(rgeos,gUnaryUnion)
importFrom(stats,setNames)
importFrom(utils,read.csv)
importMethodsFrom(raster,rasterize)
......@@ -3,6 +3,7 @@
#' Produce an epidemiological risk map by weighting multiple risk factors
#'
#' @name mapMCDA
#' @import methods
#' @docType package
NULL
......
......@@ -25,6 +25,8 @@
#' @return object of class \code{igraph}
#' @importFrom igraph graph_from_data_frame edge_attr_names
#' edge.attributes edge.attributes<-
#' @importFrom stats setNames
#' @importFrom utils read.csv
#' @export
#'
#' @examples
......@@ -126,6 +128,7 @@ must be respected:",
# ' @import igraph
setOldClass("igraph")
#' Rasterize a geographic network
#'
#' Copmute a raster with the importance of the nearest network node.
......@@ -133,7 +136,27 @@ setOldClass("igraph")
#' This assumes that the network object has node attributes "Lon" "Lat"
#' in the WGS84 reference system.
#'
#' If the graph is weighted, the weighted importance will be computed.
#' If you want the unweighted importance, remove the weight attribute
#' from the graph with \code{igraph::delete_edge_attr(x, "weight")}.
#'
#' @param x a geographic network (a igraph object with node attributes
#' "Lon" and "Lat" in the WGS84 reference system)
#' @param y a Raster* or a SpatialPolygons* object.
#' @param field character. The attribute of the network nodes to be
#' assigned to the voronoi polygon associated with each node. By
#' default it computes the \emph{importance} of each node in the
#' network. But you can manually compute any other measure of
#' interest, and pass it as a vertex attribute (see
#' \code{?igraph::`vertex_attr<-`}).
#' @param ... Other arguments passed on to
#' \code{\link[raster]{rasterize}}.
#' @importMethodsFrom raster rasterize
#' @importFrom stats setNames
#' @export
#' @name rasterize_geonetwork
#' @rdname rasterize_geonetwork
#' @aliases rasterize,igraph,Raster-method
setMethod(
rasterize, c("igraph", "Raster"),
{
......@@ -171,13 +194,11 @@ setMethod(
}
)
#' Rasterize a geographic network
#'
#' Copmute a raster with the importance of the nearest network node.
#'
#' This assumes that the network object has node attributes "Lon" "Lat"
#' in the WGS84 reference system.
#'
#' @importMethodsFrom raster rasterize
#' @param res numeric vector of length 2. Resolution in Lon/Lat of
#' rasterisation.
#' @rdname rasterize_geonetwork
#' @aliases rasterize,igraph,SpatialPolygons-method
#' @export
setMethod(
rasterize, c("igraph", "SpatialPolygons"),
......@@ -238,12 +259,14 @@ setMethod(
#'
#' @importFrom igraph decompose.graph degree gorder is.weighted
#' as_data_frame
#' @importFrom stats setNames
#'
#' @references
#' Volkova VV, Howey R, Savill NJ, Woolhouse MEJ (2010) Sheep
#' Movement Networks and the Transmission of Infectious Diseases.
#' PLoS ONE 5(6): e11185.
#' https://doi.org/10.1371/journal.pone.0011185
#' @export
#' @examples
#' g <- igraph::graph_from_literal(A --+ B --+C, A --+C, B --+D)
#' epidemic_threshold(g)
......@@ -255,6 +278,7 @@ epidemic_threshold <- function(x, beta = 1) {
UseMethod("epidemic_threshold")
}
#' @export
epidemic_threshold.igraph <- function(x, beta = 1) {
sc <- decompose.graph(x)
n_v <- lapply(sc, gorder)
......@@ -302,6 +326,7 @@ epidemic_threshold.igraph <- function(x, beta = 1) {
return(list(unweighted = epidata, weighted = epidataw))
}
#' @export
epidemic_threshold.data.frame <- function(x, beta) {
stopifnot(ncol(x) == 2)
## Individual contributions to R0
......
......@@ -15,7 +15,12 @@
#' @importFrom raster intersect
#' @importFrom rgeos gUnaryUnion
#'
#' @export
#' @examples
#' pts <- data.frame(x = c(1:2, 2), y = c(1, 1:2))
#' region <- raster::extent(c(0, 3, 0, 3))
#' sp::plot(voronoi(pts, region))
#' points(pts)
voronoi <- function(x, ext, eps = 1e-09) {
if (!requireNamespace("deldir")) {
stop("you need to first install the deldir libary")
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/network.R
\docType{methods}
\name{rasterize,igraph,Raster-method}
\alias{rasterize,igraph,Raster-method}
\title{Rasterize a geographic network}
\usage{
\S4method{rasterize}{igraph,Raster}(x, y, field = "importance", ...)
}
\description{
Copmute a raster with the importance of the nearest network node.
}
\details{
This assumes that the network object has node attributes "Lon" "Lat"
in the WGS84 reference system.
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/network.R
\docType{methods}
\name{rasterize,igraph,SpatialPolygons-method}
\name{rasterize_geonetwork}
\alias{rasterize_geonetwork}
\alias{rasterize,igraph,Raster-method}
\alias{rasterize,igraph,SpatialPolygons-method}
\title{Rasterize a geographic network}
\usage{
\S4method{rasterize}{igraph,Raster}(x, y, field = "importance", ...)
\S4method{rasterize}{igraph,SpatialPolygons}(x, y, res = resolution(y,
min_ncells = 100), ...)
}
\arguments{
\item{x}{a geographic network (a igraph object with node attributes
"Lon" and "Lat" in the WGS84 reference system)}
\item{y}{a Raster* or a SpatialPolygons* object.}
\item{field}{character. The attribute of the network nodes to be
assigned to the voronoi polygon associated with each node. By
default it computes the \emph{importance} of each node in the
network. But you can manually compute any other measure of
interest, and pass it as a vertex attribute (see
\code{?igraph::`vertex_attr<-`}).}
\item{...}{Other arguments passed on to
\code{\link[raster]{rasterize}}.}
\item{res}{numeric vector of length 2. Resolution in Lon/Lat of
rasterisation.}
}
\description{
Copmute a raster with the importance of the nearest network node.
}
\details{
This assumes that the network object has node attributes "Lon" "Lat"
in the WGS84 reference system.
If the graph is weighted, the weighted importance will be computed.
If you want the unweighted importance, remove the weight attribute
from the graph with \code{igraph::delete_edge_attr(x, "weight")}.
}
......@@ -19,6 +19,12 @@ SpatialPolygonsDataFrame.
\description{
Compute a vornoi tesselation of a map for a set of points.
}
\examples{
pts <- data.frame(x = c(1:2, 2), y = c(1, 1:2))
region <- raster::extent(c(0, 3, 0, 3))
sp::plot(voronoi(pts, region))
points(pts)
}
\author{
Borrowed from function \code{\link[dismo]{voronoi}} from
package \code{dismo} by R. Hijmans et al., which ultimately
......
......@@ -27,9 +27,7 @@ test_that("harmonise resolution and extents", {
#' All rasters are resampled to the same extent and resolution as the \emph{first}
#' raster in the list.
risk_layer(waterb, cmr$cmr_admin3, scale_target = c(0, 100))
tr <- list(
raster(nrows = 10, ncols = 10, xmn = 0, xmx = 9, ymn = 0, ymx = 9),
raster(nrows = 11, ncols = 11, xmn = 1, xmx = 10, ymn = 1, ymx = 10)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment