Skip to content

Commit

Permalink
modifications for _R_CHECK_DEPENDS_ONLY_=true
Browse files Browse the repository at this point in the history
* includes cleaned up reference test output
  • Loading branch information
edzer committed Jun 15, 2022
1 parent 6d3e931 commit 4f550e5
Show file tree
Hide file tree
Showing 61 changed files with 948 additions and 1,308 deletions.
11 changes: 6 additions & 5 deletions R/arith.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
#' # affine:
#' st_point(c(1,2)) * m + c(2,5)
#' # world in 0-360 range:
#' library(maps)
#' w = st_as_sf(map('world', plot = FALSE, fill = TRUE))
#' w2 = (st_geometry(w) + c(360,90)) %% c(360) - c(0,90)
#' w3 = st_wrap_dateline(st_set_crs(w2 - c(180,0), 4326)) + c(180,0)
#' plot(st_set_crs(w3, 4326), axes = TRUE)
#' if (require(maps, quietly = TRUE)) {
#' w = st_as_sf(map('world', plot = FALSE, fill = TRUE))
#' w2 = (st_geometry(w) + c(360,90)) %% c(360) - c(0,90)
#' w3 = st_wrap_dateline(st_set_crs(w2 - c(180,0), 4326)) + c(180,0)
#' plot(st_set_crs(w3, 4326), axes = TRUE)
#' }
#' (mp <- st_point(c(1,2)) + st_point(c(3,4))) # MULTIPOINT (1 2, 3 4)
#' mp - st_point(c(3,4)) # POINT (1 2)
#' opar = par(mfrow = c(2,2), mar = c(0, 0, 1, 0))
Expand Down
5 changes: 3 additions & 2 deletions R/bind.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ rbind.sf = function(..., deparse.level = 1) {
#' @details If you need to \code{cbind} e.g. a \code{data.frame} to an \code{sf}, use \link{data.frame} directly and use \link{st_sf} on its result, or use \link[dplyr:bind]{bind_cols}; see examples.
#' @examples
#' cbind(a,b,c) # warns
#' if (require(dplyr))
#' if (require(dplyr, quietly = TRUE))
#' dplyr::bind_cols(a,b)
#' c = st_sf(a=4, geomc = st_sfc(st_multilinestring(list(matrix(1:4,2)))), crs = crs)
#' cbind(a,b,c, sf_column_name = "geomc")
#' df = data.frame(x=3)
#' st_sf(data.frame(c, df))
#' dplyr::bind_cols(c, df)
#' if (require(dplyr, quietly = TRUE))
#' dplyr::bind_cols(c, df)
cbind.sf = function(..., deparse.level = 1, sf_column_name = NULL) {
# TODO: handle st_agr?
st_sf(data.frame(...), sf_column_name = sf_column_name)
Expand Down
4 changes: 1 addition & 3 deletions R/crs.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@ make_crs = function(x) {
#' @name st_crs
#' @examples
#' sfc = st_sfc(st_point(c(0,0)), st_point(c(1,1)))
#' library(dplyr)
#' x = sfc %>% st_set_crs(4326) %>% st_transform(3857)
#' x
#' sfc %>% st_set_crs(4326) %>% st_transform(3857)
#' @export
st_set_crs = function(x, value) {
st_crs(x) = value
Expand Down
8 changes: 5 additions & 3 deletions R/geom-transformers.R
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,11 @@ st_node.sf = function(x) {
#' @param ... ignored
#' @examples
#' sf = st_sf(a=1, geom=st_sfc(st_linestring(rbind(c(0,0),c(1,1)))), crs = 4326)
#' seg = st_segmentize(sf, units::set_units(100, km))
#' seg = st_segmentize(sf, units::set_units(0.01, rad))
#' nrow(seg$geom[[1]])
#' if (require(lwgeom, quietly = TRUE)) {
#' seg = st_segmentize(sf, units::set_units(100, km))
#' seg = st_segmentize(sf, units::set_units(0.01, rad))
#' nrow(seg$geom[[1]])
#' }
st_segmentize = function(x, dfMaxLength, ...)
UseMethod("st_segmentize")

Expand Down
3 changes: 2 additions & 1 deletion R/graticule.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#' see example.
#' @examples
#' library(sf)
#' library(maps)
#' if (require(maps, quietly = TRUE)) {
#'
#' usa = st_as_sf(map('usa', plot = FALSE, fill = TRUE))
#' laea = st_crs("+proj=laea +lat_0=30 +lon_0=-95") # Lambert equal area
Expand Down Expand Up @@ -59,6 +59,7 @@
#' srt = g$angle_end[i] - 90, pos = 3, cex = .7)
#' }))
#' plot(usa, graticule = st_crs(4326), axes = TRUE, lon = seq(-60,-130,by=-10))
#' }
st_graticule = function(x = c(-180,-90,180,90), crs = st_crs(x),
datum = st_crs(4326), ..., lon = NULL, lat = NULL, ndiscr = 100,
margin = 0.001)
Expand Down
2 changes: 1 addition & 1 deletion R/jitter.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' @param factor numeric; fractional amount of jittering to be applied
#' @details jitters coordinates with an amount such that \code{runif(1, -amount, amount)} is added to the coordinates. x- and y-coordinates are jittered independently but all coordinates of a single geometry are jittered with the same amount, meaning that the geometry shape does not change. For longlat data, a latitude correction is made such that jittering in East and North directions are identical in distance in the center of the bounding box of \code{x}.
#' @examples
#' nc = read_sf(system.file("gpkg/nc.gpkg", package="sf"))
#' nc = st_read(system.file("gpkg/nc.gpkg", package="sf"))
#' pts = st_centroid(st_geometry(nc))
#' plot(pts)
#' plot(st_jitter(pts, .05), add = TRUE, col = 'red')
Expand Down
5 changes: 3 additions & 2 deletions R/join.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ st_join = function(x, y, join, ...) UseMethod("st_join")
#' st_join(a, b, left = FALSE)
#' # two ways to aggregate y's attribute values outcome over x's geometries:
#' st_join(a, b) %>% aggregate(list(.$a.x), mean)
#' library(dplyr)
#' st_join(a, b) %>% group_by(a.x) %>% summarise(mean(a.y))
#' if (require(dplyr, quietly = TRUE)) {
#' st_join(a, b) %>% group_by(a.x) %>% summarise(mean(a.y))
#' }
#' # example of largest = TRUE:
#' nc <- st_transform(st_read(system.file("shape/nc.shp", package="sf")), 2264)
#' gr = st_sf(
Expand Down
2 changes: 1 addition & 1 deletion R/make_grid.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#' # non-default offset:
#' plot(st_make_grid(sfc, cellsize = .1, square = FALSE, offset = c(0, .05 / (sqrt(3)/2))))
#' plot(sfc, add = TRUE)
#' nc = read_sf(system.file("shape/nc.shp", package="sf"))
#' nc = st_read(system.file("shape/nc.shp", package="sf"))
#' g = st_make_grid(nc)
#' plot(g)
#' plot(st_geometry(nc), add = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion R/nearest.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#' plot(st_sfc(b2, b3), add = TRUE, col = NA, border = 'blue')
#' plot(ls, add = TRUE, col = 'red')
#'
#' nc = read_sf(system.file("gpkg/nc.gpkg", package="sf"))
#' nc = st_read(system.file("gpkg/nc.gpkg", package="sf"))
#' plot(st_geometry(nc))
#' ls = st_nearest_points(nc[1,], nc)
#' plot(ls, col = 'red', add = TRUE)
Expand Down
18 changes: 10 additions & 8 deletions R/read.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ set_utf8 = function(x) {
#' # spatial filter, as wkt:
#' wkt = st_as_text(st_geometry(nc[1,]))
#' # filter by (bbox overlaps of) first feature geometry:
#' read_sf(system.file("gpkg/nc.gpkg", package="sf"), wkt_filter = wkt)
#' st_read(system.file("gpkg/nc.gpkg", package="sf"), wkt_filter = wkt)
#' @export
st_read = function(dsn, layer, ...) UseMethod("st_read")

Expand Down Expand Up @@ -246,7 +246,7 @@ st_read.character = function(dsn, layer, ..., query = NA, options = NULL, quiet
#' # read geojson from string:
#' geojson_txt <- paste("{\"type\":\"MultiPoint\",\"coordinates\":",
#' "[[3.2,4],[3,4.6],[3.8,4.4],[3.5,3.8],[3.4,3.6],[3.9,4.5]]}")
#' x = read_sf(geojson_txt)
#' x = st_read(geojson_txt)
#' x
read_sf <- function(..., quiet = TRUE, stringsAsFactors = FALSE, as_tibble = TRUE) {
st_read(..., quiet = quiet, stringsAsFactors = stringsAsFactors, as_tibble = as_tibble)
Expand Down Expand Up @@ -369,12 +369,13 @@ abbreviate_shapefile_names = function(x) {
#' nc = st_read(system.file("shape/nc.shp", package="sf"))
#' st_write(nc, paste0(tempdir(), "/", "nc.shp"))
#' st_write(nc, paste0(tempdir(), "/", "nc.shp"), delete_layer = TRUE) # overwrites
#' data(meuse, package = "sp") # loads data.frame from sp
#' meuse_sf = st_as_sf(meuse, coords = c("x", "y"), crs = 28992)
#' # writes X and Y as columns:
#' st_write(meuse_sf, paste0(tempdir(), "/", "meuse.csv"), layer_options = "GEOMETRY=AS_XY")
#' st_write(meuse_sf, paste0(tempdir(), "/", "meuse.csv"), layer_options = "GEOMETRY=AS_WKT",
#' delete_dsn=TRUE) # overwrites
#' if (require(sp, quietly = TRUE)) {
#' data(meuse, package = "sp") # loads data.frame from sp
#' meuse_sf = st_as_sf(meuse, coords = c("x", "y"), crs = 28992)
#' # writes X and Y as columns:
#' st_write(meuse_sf, paste0(tempdir(), "/", "meuse.csv"), layer_options = "GEOMETRY=AS_XY")
#' st_write(meuse_sf, paste0(tempdir(), "/", "meuse.csv"), layer_options = "GEOMETRY=AS_WKT",
#' delete_dsn=TRUE) # overwrites
#' \dontrun{
#' library(sp)
#' example(meuse, ask = FALSE, echo = FALSE)
Expand All @@ -383,6 +384,7 @@ abbreviate_shapefile_names = function(x) {
#' demo(nc, ask = FALSE)
#' try(st_write(nc, "PG:dbname=postgis", "sids", layer_options = "OVERWRITE=true"))
#' }
#' }
#' @export
st_write = function(obj, dsn, layer, ...) UseMethod("st_write")

Expand Down
2 changes: 2 additions & 0 deletions R/sample.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ st_sample = function(x, size, ...) UseMethod("st_sample")
#' plot(x, axes = TRUE, graticule = TRUE)
#' if (sf_extSoftVersion()["proj.4"] >= "4.9.0")
#' plot(p <- st_sample(x, 1000), add = TRUE)
#' if (require(lwgeom, quietly = TRUE)) { # for st_segmentize()
#' x2 = st_transform(st_segmentize(x, 1e4), st_crs("+proj=ortho +lat_0=30 +lon_0=45"))
#' g = st_transform(st_graticule(), st_crs("+proj=ortho +lat_0=30 +lon_0=45"))
#' plot(x2, graticule = g)
#' if (sf_extSoftVersion()["proj.4"] >= "4.9.0") {
#' p2 = st_transform(p, st_crs("+proj=ortho +lat_0=30 +lon_0=45"))
#' plot(p2, add = TRUE)
#' }
#' }
#' x = st_sfc(st_polygon(list(rbind(c(0,0),c(90,0),c(90,10),c(0,90),c(0,0))))) # NOT long/lat:
#' plot(x)
#' p_exact = st_sample(x, 1000, exact = TRUE)
Expand Down
10 changes: 6 additions & 4 deletions R/sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ st_as_sf = function(x, ...) UseMethod("st_as_sf")
#' df = st_as_sf(d, wkt = "geom")
#' d$geom2 = st_sfc(pt1, pt2)
#' st_as_sf(d) # should warn
#' data(meuse, package = "sp")
#' meuse_sf = st_as_sf(meuse, coords = c("x", "y"), crs = 28992, agr = "constant")
#' meuse_sf[1:3,]
#' summary(meuse_sf)
#' if (require(sp, quietly = TRUE)) {
#' data(meuse, package = "sp")
#' meuse_sf = st_as_sf(meuse, coords = c("x", "y"), crs = 28992, agr = "constant")
#' meuse_sf[1:3,]
#' summary(meuse_sf)
#' }
#' @export
st_as_sf.data.frame = function(x, ..., agr = NA_agr_, coords, wkt,
dim = "XYZ", remove = TRUE, na.fail = TRUE, sf_column_name = NULL) {
Expand Down
5 changes: 4 additions & 1 deletion R/sp.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#' @name st_as_sf
#' @examples
#' library(sp)
#' if (require(sp, quietly = TRUE)) {
#' x = rbind(c(-1,-1), c(1,-1), c(1,1), c(-1,1), c(-1,-1))
#' x1 = 0.1 * x + 0.1
#' x2 = 0.1 * x + 0.4
Expand Down Expand Up @@ -52,6 +52,7 @@
#' pol.grd = as(meuse.grid, "SpatialPolygonsDataFrame")
#' # summary(st_as_sf(pol.grd))
#' # summary(st_as_sf(as(pol.grd, "SpatialLinesDataFrame")))
#' }
#' @export
st_as_sf.Spatial = function(x, ...) {
if ("data" %in% slotNames(x))
Expand Down Expand Up @@ -238,6 +239,7 @@ setAs("XY", "Spatial", function(from) as(st_sfc(from), "Spatial"))
#' @export
#' @examples
#' nc <- st_read(system.file("shape/nc.shp", package="sf"))
#' if (require(sp, quietly = TRUE)) {
#' # convert to SpatialPolygonsDataFrame
#' spdf <- as_Spatial(nc)
#' # identical to
Expand All @@ -246,6 +248,7 @@ setAs("XY", "Spatial", function(from) as(st_sfc(from), "Spatial"))
#' as(st_geometry(nc), "Spatial")
#' # back to sf
#' as(spdf, "sf")
#' }
as_Spatial = function(from, cast = TRUE, IDs = paste0("ID", seq_along(from))) {
if (inherits(from, "sf")) {
geom = st_geometry(from)
Expand Down
Loading

0 comments on commit 4f550e5

Please sign in to comment.