Skip to content

Commit a2cfe63

Browse files
committed
accept NULL or NA for datum in st_graticule
related to tidyverse/ggplot2#2200
1 parent b126b6e commit a2cfe63

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

R/graticule.R

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
#' better than a graticule.
1414
#'
1515
#' @export
16-
#' @param x object of class \code{sf}, \code{sfc} or \code{sfg} or numeric vector with bounding box (minx,miny,maxx,maxy).
16+
#' @param x object of class \code{sf}, \code{sfc} or \code{sfg} or numeric vector with bounding box given as (minx, miny, maxx, maxy).
1717
#' @param crs object of class \code{crs}, with the display coordinate reference system
18-
#' @param datum object of class \code{crs}, with the coordinate reference system for the graticules
18+
#' @param datum either an object of class \code{crs} with the coordinate reference system for the graticules, or \code{NULL} or \code{NA} in which case a grid in the coordinate system of \code{x} is drawn.
1919
#' @param lon numeric; degrees east for the meridians
2020
#' @param lat numeric; degrees north for the parallels
2121
#' @param ndiscr integer; number of points to discretize a parallel or meridian
@@ -73,6 +73,9 @@ st_graticule = function(x = c(-180,-90,180,90), crs = st_crs(x),
7373

7474
if (is.null(crs))
7575
crs = NA_crs_
76+
77+
if (is.null(datum) || is.na(datum))
78+
datum = crs
7679

7780
# Get the bounding box of the plotting space, in crs
7881
bb = if (inherits(x, "sf") || inherits(x, "sfc") || inherits(x, "sfg"))

man/st_graticule.Rd

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

tests/graticule.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ plot(nc[1], graticule = st_crs(nc), axes = TRUE)
4545
g = st_graticule()
4646

4747
library(ggplot2)
48-
if (utils::packageVersion("ggplot2") >= "2.2.1") {
48+
if (utils::packageVersion("ggplot2") > "2.2.1") {
4949
ggplot() + geom_sf(data = st_set_crs(nc, NA_crs_)) # NA_crs_ for crs
5050
}

tests/graticule.Rout.save

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch"
3-
Copyright (C) 2016 The R Foundation for Statistical Computing
2+
R version 3.4.1 (2017-06-30) -- "Single Candle"
3+
Copyright (C) 2017 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu (64-bit)
55

66
R is free software and comes with ABSOLUTELY NO WARRANTY.
@@ -61,6 +61,11 @@ Type 'q()' to quit R.
6161
>
6262
> g = st_graticule()
6363
>
64+
> library(ggplot2)
65+
> if (utils::packageVersion("ggplot2") > "2.2.1") {
66+
+ ggplot() + geom_sf(data = st_set_crs(nc, NA_crs_)) # NA_crs_ for crs
67+
+ }
68+
>
6469
> proc.time()
6570
user system elapsed
66-
0.972 0.024 0.994
71+
2.212 0.296 2.198

0 commit comments

Comments
 (0)