Skip to content

Commit 1e6ef81

Browse files
committed
use compareVersion() everywhere
fixes #2512
1 parent 4426011 commit 1e6ef81

9 files changed

+17
-17
lines changed

R/crs.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ make_crs = function(x) {
187187
x
188188
else if (is.character(x)) {
189189
if (grepl("+init=epsg:", x) &&
190-
sf_extSoftVersion()[["proj.4"]] >= "6.0.0" &&
191-
sf_extSoftVersion()[["proj.4"]] < "6.3.1") { # nocov start FIXME:
190+
compareVersion(sf_extSoftVersion()[["proj.4"]], "6.0.0") >= 0 &&
191+
compareVersion(sf_extSoftVersion()[["proj.4"]], "6.3.1") < 0) { # nocov start FIXME:
192192
x = strsplit(x, " ")[[1]]
193193
if (length(x) > 1)
194194
warning(paste("the following proj4string elements are ignored:",
@@ -361,7 +361,7 @@ st_as_text.crs = function(x, ..., projjson = FALSE, pretty = FALSE) {
361361
if (is.na(x))
362362
NA_character_
363363
else if (projjson) {
364-
if (sf_extSoftVersion()["GDAL"] < "3.1.0" || sf_extSoftVersion()["proj.4"] < "6.2.0")
364+
if (compareVersion(sf_extSoftVersion()["GDAL"], "3.1.0") == -1 || compareVersion(sf_extSoftVersion()["proj.4"], "6.2.0") == -1)
365365
stop("ProjJson requires GDAL >= 3.1.0 and PROJ >= 6.2.0")
366366
crs_parameters(x)$ProjJson
367367
} else { # wkt:
@@ -504,7 +504,7 @@ st_crs.Spatial = function(x, ...) {
504504
#' st_axis_order() # query default: FALSE means interpret pt as (longitude latitude)
505505
#' st_transform(pt, 3857)[[1]]
506506
#' old_value = FALSE
507-
#' if (sf_extSoftVersion()["GDAL"] >= "2.5.0")
507+
#' if (compareVersion(sf_extSoftVersion()["GDAL"], "2.5.0") >= 0)
508508
#' (old_value = st_axis_order(TRUE))
509509
#' # now interpret pt as (latitude longitude), as EPSG:4326 prescribes:
510510
#' st_axis_order() # query current value

R/gdal_utils.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ resampling_method = function(option = "near") {
3737
#' @seealso \link{gdal_addo} for adding overlays to a raster file; \link{st_layers} to query geometry type(s) and crs from layers in a (vector) data source
3838
#' @examples
3939
#'
40-
#' if (sf_extSoftVersion()["GDAL"] > "2.1.0") {
40+
#' if (compareVersion(sf_extSoftVersion()["GDAL"], "2.1.0") == 1) {
4141
#' # info utils can be used to list information about a raster
4242
#' # dataset. More info: https://gdal.org/programs/gdalinfo.html
4343
#' in_file <- system.file("tif/geomatrix.tif", package = "sf")

R/proj.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ sf_project = function(from = character(0), to = character(0), pts, keep = FALSE,
5858
stop("'keep' must be single-length non-NA logical value")
5959
proj_from_crs = function(x) {
6060
if (inherits(x, "crs")) {
61-
x = if (sf_extSoftVersion()["proj.4"] >= "6.0.0")
61+
x = if (compareVersion(sf_extSoftVersion()["proj.4"], "6.0.0") >= 0)
6262
x$wkt
6363
else
6464
x$proj4string

R/sample.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ st_sample = function(x, size, ...) UseMethod("st_sample")
5252
#' plot(p2, add = TRUE, pch = 2)
5353
#' x = st_sfc(st_polygon(list(rbind(c(0,0),c(90,0),c(90,90),c(0,90),c(0,0)))), crs = st_crs(4326))
5454
#' plot(x, axes = TRUE, graticule = TRUE)
55-
#' if (sf_extSoftVersion()["proj.4"] >= "4.9.0")
55+
#' if (compareVersion(sf_extSoftVersion()["proj.4"], "4.9.0") >= 0)
5656
#' plot(p <- st_sample(x, 1000), add = TRUE)
5757
#' if (require(lwgeom, quietly = TRUE)) { # for st_segmentize()
5858
#' x2 = st_transform(st_segmentize(x, 1e4), st_crs("+proj=ortho +lat_0=30 +lon_0=45"))
5959
#' g = st_transform(st_graticule(), st_crs("+proj=ortho +lat_0=30 +lon_0=45"))
6060
#' plot(x2, graticule = g)
61-
#' if (sf_extSoftVersion()["proj.4"] >= "4.9.0") {
61+
#' if (compareVersion(sf_extSoftVersion()["proj.4"], "4.9.0") >= 0) {
6262
#' p2 = st_transform(p, st_crs("+proj=ortho +lat_0=30 +lon_0=45"))
6363
#' plot(p2, add = TRUE)
6464
#' }
@@ -72,7 +72,7 @@ st_sample = function(x, size, ...) UseMethod("st_sample")
7272
#' x = st_sfc(st_polygon(list(rbind(c(-180,-90),c(180,-90),c(180,90),c(-180,90),c(-180,-90)))),
7373
#' crs=st_crs(4326))
7474
#' # FIXME:
75-
#' #if (sf_extSoftVersion()["proj.4"] >= "4.9.0") {
75+
#' #if (compareVersion(sf_extSoftVersion()["proj.4"], "4.9.0") >= 0) {
7676
#' # p = st_sample(x, 1000)
7777
#' # st_sample(p, 3)
7878
#' #}

R/transform.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ st_transform = function(x, crs, ...) UseMethod("st_transform")
8989
#' @export
9090
#' @examples
9191
#' st_transform(st_sf(a=2:1, geom=sfc), "EPSG:3857")
92-
#' if (sf_extSoftVersion()["GDAL"] >= "3.0.0") {
92+
#' if (compareVersion(sf_extSoftVersion()["GDAL"], "3.0.0") >= 0) {
9393
#' st_transform(sfc, pipeline =
9494
#' "+proj=pipeline +step +proj=axisswap +order=2,1") # reverse axes
9595
#' st_transform(sfc, pipeline =
@@ -170,7 +170,7 @@ st_transform.sfg = function(x, crs = st_crs(x), ...) {
170170
#' @param densify integer, number of points for discretizing lines between bounding box corner points; see Details
171171
#' @details the method for `bbox` objects densifies lines for geographic coordinates along Cartesian lines, not great circle arcs
172172
st_transform.bbox = function(x, crs, ..., densify = 21) {
173-
if (sf_extSoftVersion()["GDAL"] >= "3.4.0")
173+
if (compareVersion(sf_extSoftVersion()["GDAL"], "3.4.0") >= 0)
174174
st_bbox(CPL_transform_bounds(x, st_crs(crs), densify), crs = crs)
175175
else
176176
stop("method not available for GDAL: ", sf_extSoftVersion()["GDAL"])

man/gdal_utils.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/st_crs.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/st_sample.Rd

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/st_transform.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)