Skip to content

Commit ff51048

Browse files
authored
Merge pull request #2187 from MichaelChirico/anyna
Use anyNA() where possible
2 parents effea0a + 1e10819 commit ff51048

File tree

8 files changed

+10
-10
lines changed

8 files changed

+10
-10
lines changed

R/agr.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,5 @@ summarize_agr = function(x) {
9292

9393
all_constant = function(x) {
9494
x = attr(x, "agr")
95-
!(any(is.na(x)) || any(!(x %in% c("identity", "constant"))))
95+
!anyNA(x) && all(x %in% c("identity", "constant"))
9696
}

R/db.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ schema_table <- function(conn, table, public = "public") {
192192
else if (length(table) > 2)
193193
stop("table cannot be longer than 2 (schema, table)", call. = FALSE)
194194

195-
if (any(is.na(table)))
195+
if (anyNA(table))
196196
stop("table and schema cannot be NA", call. = FALSE)
197197

198198
return(table)

R/geom-transformers.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ st_buffer.sfg = function(x, dist, nQuadSegs = 30,
8585
if (is.na(mitreLimit) || !mitreLimit > 0) stop("mitreLimit must be > 0")
8686
if (is.na(ecs)) stop("endCapStyle must be 'ROUND', 'FLAT', or 'SQUARE'")
8787
if (is.na(js)) stop("joinStyle must be 'ROUND', 'MITRE', or 'BEVEL'")
88-
if (any(is.na(singleSide))) stop("singleSide should be TRUE or FALSE")
88+
if (anyNA(singleSide)) stop("singleSide should be TRUE or FALSE")
8989
styls$with_styles = TRUE
9090
styls$endCapStyle = ecs
9191
styls$joinStyle = js

R/grid.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ st_as_grob = function(x, ...) UseMethod("st_as_grob")
88

99
#' @export
1010
st_as_grob.POINT = function(x, pch = 1, size = unit(1, "char"), default.units = "native", name = NULL, gp = gpar(), vp = NULL, ...) {
11-
if (any(is.na(x)))
11+
if (anyNA(x))
1212
nullGrob()
1313
else
1414
pointsGrob(x[1], x[2], pch = pch, size = size, default.units = default.units, name = name, gp = gp, vp = vp)

R/plot.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ swap_axes_if_needed = function(x) {
290290
#' @export
291291
get_key_pos = function(x, ...) {
292292
bb = st_bbox(x)
293-
if (any(is.na(bb)) || (inherits(x, "sf") && ncol(x) > 2))
293+
if (anyNA(bb) || (inherits(x, "sf") && ncol(x) > 2))
294294
NULL
295295
else {
296296
pin = par("pin") # (width, height)
@@ -580,7 +580,7 @@ plot_sf = function(x, xlim = NULL, ylim = NULL, asp = NA, axes = FALSE, bgc = pa
580580
if (is.na(asp))
581581
asp <- ifelse(isTRUE(st_is_longlat(x)), 1/cos((mean(ylim) * pi)/180), 1.0)
582582

583-
if (any(is.na(bbox)))
583+
if (anyNA(bbox))
584584
stop("NA value(s) in bounding box. Trying to plot empty geometries?")
585585

586586
plot.new()

R/sf.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ st_as_sf.data.frame = function(x, ..., agr = NA_agr_, coords, wkt,
4545
x$geometry = st_as_sfc(as.character(x[[wkt]]))
4646
} else if (! missing(coords)) {
4747
cc = as.data.frame(lapply(x[coords], as.numeric))
48-
if (na.fail && any(is.na(cc)))
48+
if (na.fail && anyNA(cc))
4949
stop("missing values in coordinates not allowed")
5050
# classdim = getClassDim(rep(0, length(coords)), length(coords), dim, "POINT")
5151
x$geometry = structure( points_rcpp(as.matrix(cc), dim),

R/sfc.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ st_sfc = function(..., crs = NA_crs_, precision = 0.0, check_ring_dir = FALSE, d
9898

9999
# compute bbox, if not set:
100100
bb = attr(lst, "bbox")
101-
if (is.null(bb) || any(is.na(bb)) || recompute_bbox)
101+
if (is.null(bb) || anyNA(bb) || recompute_bbox)
102102
attr(lst, "bbox") = compute_bbox(lst)
103103

104104
# compute z_range, if dims permit and not set
105105
zr = attr(lst, "z_range")
106-
if (is.null(zr) || any(is.na(zr))) {
106+
if (is.null(zr) || anyNA(zr)) {
107107
u <- dims_and_types[[1]]
108108
if( "XYZM" %in% u ) {
109109
attr(lst, "z_range") = compute_z_range(lst)

R/stars.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ xy_from_colrow = function(x, geotransform, inverse = FALSE) {
110110
# Yp = geotransform[3] + P*geotransform[4] + L*geotransform[5];
111111
if (inverse) {
112112
geotransform = gdal_inv_geotransform(geotransform) # nocov start
113-
if (any(is.na(geotransform)))
113+
if (anyNA(geotransform))
114114
stop("geotransform not invertible") # nocov end
115115
}
116116
stopifnot(ncol(x) == 2)

0 commit comments

Comments
 (0)