Skip to content

Commit 4f550e5

Browse files
committed
modifications for _R_CHECK_DEPENDS_ONLY_=true
* includes cleaned up reference test output
1 parent 6d3e931 commit 4f550e5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+948
-1308
lines changed

R/arith.R

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
#' # affine:
2020
#' st_point(c(1,2)) * m + c(2,5)
2121
#' # world in 0-360 range:
22-
#' library(maps)
23-
#' w = st_as_sf(map('world', plot = FALSE, fill = TRUE))
24-
#' w2 = (st_geometry(w) + c(360,90)) %% c(360) - c(0,90)
25-
#' w3 = st_wrap_dateline(st_set_crs(w2 - c(180,0), 4326)) + c(180,0)
26-
#' plot(st_set_crs(w3, 4326), axes = TRUE)
22+
#' if (require(maps, quietly = TRUE)) {
23+
#' w = st_as_sf(map('world', plot = FALSE, fill = TRUE))
24+
#' w2 = (st_geometry(w) + c(360,90)) %% c(360) - c(0,90)
25+
#' w3 = st_wrap_dateline(st_set_crs(w2 - c(180,0), 4326)) + c(180,0)
26+
#' plot(st_set_crs(w3, 4326), axes = TRUE)
27+
#' }
2728
#' (mp <- st_point(c(1,2)) + st_point(c(3,4))) # MULTIPOINT (1 2, 3 4)
2829
#' mp - st_point(c(3,4)) # POINT (1 2)
2930
#' opar = par(mfrow = c(2,2), mar = c(0, 0, 1, 0))

R/bind.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ rbind.sf = function(..., deparse.level = 1) {
4848
#' @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.
4949
#' @examples
5050
#' cbind(a,b,c) # warns
51-
#' if (require(dplyr))
51+
#' if (require(dplyr, quietly = TRUE))
5252
#' dplyr::bind_cols(a,b)
5353
#' c = st_sf(a=4, geomc = st_sfc(st_multilinestring(list(matrix(1:4,2)))), crs = crs)
5454
#' cbind(a,b,c, sf_column_name = "geomc")
5555
#' df = data.frame(x=3)
5656
#' st_sf(data.frame(c, df))
57-
#' dplyr::bind_cols(c, df)
57+
#' if (require(dplyr, quietly = TRUE))
58+
#' dplyr::bind_cols(c, df)
5859
cbind.sf = function(..., deparse.level = 1, sf_column_name = NULL) {
5960
# TODO: handle st_agr?
6061
st_sf(data.frame(...), sf_column_name = sf_column_name)

R/crs.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,7 @@ make_crs = function(x) {
228228
#' @name st_crs
229229
#' @examples
230230
#' sfc = st_sfc(st_point(c(0,0)), st_point(c(1,1)))
231-
#' library(dplyr)
232-
#' x = sfc %>% st_set_crs(4326) %>% st_transform(3857)
233-
#' x
231+
#' sfc %>% st_set_crs(4326) %>% st_transform(3857)
234232
#' @export
235233
st_set_crs = function(x, value) {
236234
st_crs(x) = value

R/geom-transformers.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,11 @@ st_node.sf = function(x) {
574574
#' @param ... ignored
575575
#' @examples
576576
#' sf = st_sf(a=1, geom=st_sfc(st_linestring(rbind(c(0,0),c(1,1)))), crs = 4326)
577-
#' seg = st_segmentize(sf, units::set_units(100, km))
578-
#' seg = st_segmentize(sf, units::set_units(0.01, rad))
579-
#' nrow(seg$geom[[1]])
577+
#' if (require(lwgeom, quietly = TRUE)) {
578+
#' seg = st_segmentize(sf, units::set_units(100, km))
579+
#' seg = st_segmentize(sf, units::set_units(0.01, rad))
580+
#' nrow(seg$geom[[1]])
581+
#' }
580582
st_segmentize = function(x, dfMaxLength, ...)
581583
UseMethod("st_segmentize")
582584

R/graticule.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#' see example.
2828
#' @examples
2929
#' library(sf)
30-
#' library(maps)
30+
#' if (require(maps, quietly = TRUE)) {
3131
#'
3232
#' usa = st_as_sf(map('usa', plot = FALSE, fill = TRUE))
3333
#' laea = st_crs("+proj=laea +lat_0=30 +lon_0=-95") # Lambert equal area
@@ -59,6 +59,7 @@
5959
#' srt = g$angle_end[i] - 90, pos = 3, cex = .7)
6060
#' }))
6161
#' plot(usa, graticule = st_crs(4326), axes = TRUE, lon = seq(-60,-130,by=-10))
62+
#' }
6263
st_graticule = function(x = c(-180,-90,180,90), crs = st_crs(x),
6364
datum = st_crs(4326), ..., lon = NULL, lat = NULL, ndiscr = 100,
6465
margin = 0.001)

R/jitter.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#' @param factor numeric; fractional amount of jittering to be applied
66
#' @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}.
77
#' @examples
8-
#' nc = read_sf(system.file("gpkg/nc.gpkg", package="sf"))
8+
#' nc = st_read(system.file("gpkg/nc.gpkg", package="sf"))
99
#' pts = st_centroid(st_geometry(nc))
1010
#' plot(pts)
1111
#' plot(st_jitter(pts, .05), add = TRUE, col = 'red')

R/join.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ st_join = function(x, y, join, ...) UseMethod("st_join")
105105
#' st_join(a, b, left = FALSE)
106106
#' # two ways to aggregate y's attribute values outcome over x's geometries:
107107
#' st_join(a, b) %>% aggregate(list(.$a.x), mean)
108-
#' library(dplyr)
109-
#' st_join(a, b) %>% group_by(a.x) %>% summarise(mean(a.y))
108+
#' if (require(dplyr, quietly = TRUE)) {
109+
#' st_join(a, b) %>% group_by(a.x) %>% summarise(mean(a.y))
110+
#' }
110111
#' # example of largest = TRUE:
111112
#' nc <- st_transform(st_read(system.file("shape/nc.shp", package="sf")), 2264)
112113
#' gr = st_sf(

R/make_grid.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#' # non-default offset:
2121
#' plot(st_make_grid(sfc, cellsize = .1, square = FALSE, offset = c(0, .05 / (sqrt(3)/2))))
2222
#' plot(sfc, add = TRUE)
23-
#' nc = read_sf(system.file("shape/nc.shp", package="sf"))
23+
#' nc = st_read(system.file("shape/nc.shp", package="sf"))
2424
#' g = st_make_grid(nc)
2525
#' plot(g)
2626
#' plot(st_geometry(nc), add = TRUE)

R/nearest.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#' plot(st_sfc(b2, b3), add = TRUE, col = NA, border = 'blue')
2424
#' plot(ls, add = TRUE, col = 'red')
2525
#'
26-
#' nc = read_sf(system.file("gpkg/nc.gpkg", package="sf"))
26+
#' nc = st_read(system.file("gpkg/nc.gpkg", package="sf"))
2727
#' plot(st_geometry(nc))
2828
#' ls = st_nearest_points(nc[1,], nc)
2929
#' plot(ls, col = 'red', add = TRUE)

R/read.R

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ set_utf8 = function(x) {
121121
#' # spatial filter, as wkt:
122122
#' wkt = st_as_text(st_geometry(nc[1,]))
123123
#' # filter by (bbox overlaps of) first feature geometry:
124-
#' read_sf(system.file("gpkg/nc.gpkg", package="sf"), wkt_filter = wkt)
124+
#' st_read(system.file("gpkg/nc.gpkg", package="sf"), wkt_filter = wkt)
125125
#' @export
126126
st_read = function(dsn, layer, ...) UseMethod("st_read")
127127

@@ -246,7 +246,7 @@ st_read.character = function(dsn, layer, ..., query = NA, options = NULL, quiet
246246
#' # read geojson from string:
247247
#' geojson_txt <- paste("{\"type\":\"MultiPoint\",\"coordinates\":",
248248
#' "[[3.2,4],[3,4.6],[3.8,4.4],[3.5,3.8],[3.4,3.6],[3.9,4.5]]}")
249-
#' x = read_sf(geojson_txt)
249+
#' x = st_read(geojson_txt)
250250
#' x
251251
read_sf <- function(..., quiet = TRUE, stringsAsFactors = FALSE, as_tibble = TRUE) {
252252
st_read(..., quiet = quiet, stringsAsFactors = stringsAsFactors, as_tibble = as_tibble)
@@ -369,12 +369,13 @@ abbreviate_shapefile_names = function(x) {
369369
#' nc = st_read(system.file("shape/nc.shp", package="sf"))
370370
#' st_write(nc, paste0(tempdir(), "/", "nc.shp"))
371371
#' st_write(nc, paste0(tempdir(), "/", "nc.shp"), delete_layer = TRUE) # overwrites
372-
#' data(meuse, package = "sp") # loads data.frame from sp
373-
#' meuse_sf = st_as_sf(meuse, coords = c("x", "y"), crs = 28992)
374-
#' # writes X and Y as columns:
375-
#' st_write(meuse_sf, paste0(tempdir(), "/", "meuse.csv"), layer_options = "GEOMETRY=AS_XY")
376-
#' st_write(meuse_sf, paste0(tempdir(), "/", "meuse.csv"), layer_options = "GEOMETRY=AS_WKT",
377-
#' delete_dsn=TRUE) # overwrites
372+
#' if (require(sp, quietly = TRUE)) {
373+
#' data(meuse, package = "sp") # loads data.frame from sp
374+
#' meuse_sf = st_as_sf(meuse, coords = c("x", "y"), crs = 28992)
375+
#' # writes X and Y as columns:
376+
#' st_write(meuse_sf, paste0(tempdir(), "/", "meuse.csv"), layer_options = "GEOMETRY=AS_XY")
377+
#' st_write(meuse_sf, paste0(tempdir(), "/", "meuse.csv"), layer_options = "GEOMETRY=AS_WKT",
378+
#' delete_dsn=TRUE) # overwrites
378379
#' \dontrun{
379380
#' library(sp)
380381
#' example(meuse, ask = FALSE, echo = FALSE)
@@ -383,6 +384,7 @@ abbreviate_shapefile_names = function(x) {
383384
#' demo(nc, ask = FALSE)
384385
#' try(st_write(nc, "PG:dbname=postgis", "sids", layer_options = "OVERWRITE=true"))
385386
#' }
387+
#' }
386388
#' @export
387389
st_write = function(obj, dsn, layer, ...) UseMethod("st_write")
388390

R/sample.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@ st_sample = function(x, size, ...) UseMethod("st_sample")
4646
#' plot(x, axes = TRUE, graticule = TRUE)
4747
#' if (sf_extSoftVersion()["proj.4"] >= "4.9.0")
4848
#' plot(p <- st_sample(x, 1000), add = TRUE)
49+
#' if (require(lwgeom, quietly = TRUE)) { # for st_segmentize()
4950
#' x2 = st_transform(st_segmentize(x, 1e4), st_crs("+proj=ortho +lat_0=30 +lon_0=45"))
5051
#' g = st_transform(st_graticule(), st_crs("+proj=ortho +lat_0=30 +lon_0=45"))
5152
#' plot(x2, graticule = g)
5253
#' if (sf_extSoftVersion()["proj.4"] >= "4.9.0") {
5354
#' p2 = st_transform(p, st_crs("+proj=ortho +lat_0=30 +lon_0=45"))
5455
#' plot(p2, add = TRUE)
5556
#' }
57+
#' }
5658
#' 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:
5759
#' plot(x)
5860
#' p_exact = st_sample(x, 1000, exact = TRUE)

R/sf.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ st_as_sf = function(x, ...) UseMethod("st_as_sf")
2929
#' df = st_as_sf(d, wkt = "geom")
3030
#' d$geom2 = st_sfc(pt1, pt2)
3131
#' st_as_sf(d) # should warn
32-
#' data(meuse, package = "sp")
33-
#' meuse_sf = st_as_sf(meuse, coords = c("x", "y"), crs = 28992, agr = "constant")
34-
#' meuse_sf[1:3,]
35-
#' summary(meuse_sf)
32+
#' if (require(sp, quietly = TRUE)) {
33+
#' data(meuse, package = "sp")
34+
#' meuse_sf = st_as_sf(meuse, coords = c("x", "y"), crs = 28992, agr = "constant")
35+
#' meuse_sf[1:3,]
36+
#' summary(meuse_sf)
37+
#' }
3638
#' @export
3739
st_as_sf.data.frame = function(x, ..., agr = NA_agr_, coords, wkt,
3840
dim = "XYZ", remove = TRUE, na.fail = TRUE, sf_column_name = NULL) {

R/sp.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#' @name st_as_sf
2525
#' @examples
26-
#' library(sp)
26+
#' if (require(sp, quietly = TRUE)) {
2727
#' x = rbind(c(-1,-1), c(1,-1), c(1,1), c(-1,1), c(-1,-1))
2828
#' x1 = 0.1 * x + 0.1
2929
#' x2 = 0.1 * x + 0.4
@@ -52,6 +52,7 @@
5252
#' pol.grd = as(meuse.grid, "SpatialPolygonsDataFrame")
5353
#' # summary(st_as_sf(pol.grd))
5454
#' # summary(st_as_sf(as(pol.grd, "SpatialLinesDataFrame")))
55+
#' }
5556
#' @export
5657
st_as_sf.Spatial = function(x, ...) {
5758
if ("data" %in% slotNames(x))
@@ -238,6 +239,7 @@ setAs("XY", "Spatial", function(from) as(st_sfc(from), "Spatial"))
238239
#' @export
239240
#' @examples
240241
#' nc <- st_read(system.file("shape/nc.shp", package="sf"))
242+
#' if (require(sp, quietly = TRUE)) {
241243
#' # convert to SpatialPolygonsDataFrame
242244
#' spdf <- as_Spatial(nc)
243245
#' # identical to
@@ -246,6 +248,7 @@ setAs("XY", "Spatial", function(from) as(st_sfc(from), "Spatial"))
246248
#' as(st_geometry(nc), "Spatial")
247249
#' # back to sf
248250
#' as(spdf, "sf")
251+
#' }
249252
as_Spatial = function(from, cast = TRUE, IDs = paste0("ID", seq_along(from))) {
250253
if (inherits(from, "sf")) {
251254
geom = st_geometry(from)

0 commit comments

Comments
 (0)