From 6df8a7b9a64254b35b08df95332a63777e1cadb4 Mon Sep 17 00:00:00 2001 From: aho Date: Tue, 26 Apr 2022 10:56:34 +0200 Subject: [PATCH] Change any(is.na( to anyNA --- R/CDORemap.R | 4 ++-- R/Cluster.R | 2 +- R/ColorBar.R | 4 ++-- R/EOF.R | 2 +- R/Eno.R | 2 +- R/Histo2Hindcast.R | 2 +- R/Load.R | 14 +++++++------- R/Utils.R | 4 ++-- man/Cluster.Rd | 2 +- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/R/CDORemap.R b/R/CDORemap.R index 00824de..56dcec7 100644 --- a/R/CDORemap.R +++ b/R/CDORemap.R @@ -222,10 +222,10 @@ CDORemap <- function(data_array = NULL, lons, lats, grid, method, if (!is.numeric(lons) || !is.numeric(lats)) { stop("Expected numeric 'lons' and 'lats'.") } - if (any(is.na(lons > 0))) { + if (anyNA(lons > 0)) { stop("Found invalid values in 'lons'.") } - if (any(is.na(lats > 0))) { + if (anyNA(lats > 0)) { stop("Found invalid values in 'lats'.") } if (is.null(dim(lons))) { diff --git a/R/Cluster.R b/R/Cluster.R index 8f40118..d6c5dff 100644 --- a/R/Cluster.R +++ b/R/Cluster.R @@ -53,7 +53,7 @@ #' are same as 'data' without 'space_dim'. #'} #'\item{$centers}{ -#' A nemeric array of cluster centres or centroids (e.g. [1:K, 1:spatial degrees +#' A numeric array of cluster centres or centroids (e.g. [1:K, 1:spatial degrees #' of freedom]). The rest dimensions are same as 'data' except 'time_dim' #' and 'space_dim'. #'} diff --git a/R/ColorBar.R b/R/ColorBar.R index 206f68d..286b115 100644 --- a/R/ColorBar.R +++ b/R/ColorBar.R @@ -180,7 +180,7 @@ ColorBar <- function(brks = NULL, cols = NULL, vertical = TRUE, if (!is.null(var_limits)) { if (!(is.numeric(var_limits) && (length(var_limits) == 2))) { stop("Parameter 'var_limits' must be a numeric vector of length 2.") - } else if (any(is.na(var_limits))) { + } else if (anyNA(var_limits)) { stop("Parameter 'var_limits' must not contain NA values.") } else if (any(is.infinite(var_limits))) { stop("Parameter 'var_limits' must not contain infinite values.") @@ -210,7 +210,7 @@ ColorBar <- function(brks = NULL, cols = NULL, vertical = TRUE, brks <- length(cols) + 1 } } - if (is.null(bar_limits) || any(is.na(bar_limits))) { + if (is.null(bar_limits) || anyNA(bar_limits)) { # var_limits is defined if (is.null(bar_limits)) { bar_limits <- c(NA, NA) diff --git a/R/EOF.R b/R/EOF.R index 8f8d640..d5c79a6 100644 --- a/R/EOF.R +++ b/R/EOF.R @@ -200,7 +200,7 @@ EOF <- function(ano, lat, lon, time_dim = 'sdate', space_dim = c('lat', 'lon'), # Check if all the time steps at one grid point are NA-consistent. # The grid point should have all NAs or no NA along time dim. - if (any(is.na(ano))) { + if (anyNA(ano)) { ano_latlon <- array(ano, dim = c(nt, ny * nx)) # [time, lat*lon] na_ind <- which(is.na(ano_latlon), arr.ind = T) if (dim(na_ind)[1] != nt * length(unique(na_ind[, 2]))) { diff --git a/R/Eno.R b/R/Eno.R index 8c8d16b..e2324de 100644 --- a/R/Eno.R +++ b/R/Eno.R @@ -58,7 +58,7 @@ Eno <- function(data, time_dim = 'sdate', na.action = na.pass, ncores = NULL) { as.character(substitute(na.action)) != c("na.fail")) { stop("Parameter 'na.action' must be a function either na.pass or na.fail.") } - if(as.character(substitute(na.action))== c("na.fail") && any(is.na(data))) { + if(as.character(substitute(na.action))== c("na.fail") && anyNA(data)) { stop(paste0("Calculation fails because NA is found in paratemter 'data', ", "which is not accepted when ", "parameter 'na.action' = na.fail.")) diff --git a/R/Histo2Hindcast.R b/R/Histo2Hindcast.R index 5657457..f910a9a 100644 --- a/R/Histo2Hindcast.R +++ b/R/Histo2Hindcast.R @@ -80,7 +80,7 @@ Histo2Hindcast <- function(data, sdatesin, sdatesout, nleadtimesout, if (!is.character(sdatesout) | !is.vector(sdatesout)) { stop(paste0("Parameter 'sdatesout' must be a vector of character in the ", "format 'YYYYMMDD' or 'YYYYMM'.")) - } else if (!all(nchar(sdatesout) %in% c(6, 8)) | any(is.na(as.numeric(sdatesin)))) { + } else if (!all(nchar(sdatesout) %in% c(6, 8)) | anyNA(as.numeric(sdatesin))) { stop(paste0("Parameter 'sdatesout' must be a vector of character in the ", "format 'YYYYMMDD' or 'YYYYMM'.")) } diff --git a/R/Load.R b/R/Load.R index 955c894..cdb30be 100644 --- a/R/Load.R +++ b/R/Load.R @@ -992,7 +992,7 @@ Load <- function(var, exp = NULL, obs = NULL, sdates, nmember = NULL, if (is.null(sdates)) { stop("Error: parameter 'sdates' must be provided.") } - if (!is.character(sdates) || !all(nchar(sdates) == 8) || any(is.na(strtoi(sdates)))) { + if (!is.character(sdates) || !all(nchar(sdates) == 8) || anyNA(strtoi(sdates))) { stop("Error: parameter 'sdates' is incorrect. All starting dates should be a character string in the format 'YYYYMMDD'.") } @@ -1007,7 +1007,7 @@ Load <- function(var, exp = NULL, obs = NULL, sdates, nmember = NULL, } if (length(nmember) != length(exp)) { stop("Error: 'nmember' must contain as many values as 'exp'.") - } else if (any(is.na(nmember))) { + } else if (anyNA(nmember)) { nmember[which(is.na(nmember))] <- max(nmember, na.rm = TRUE) } } @@ -1023,7 +1023,7 @@ Load <- function(var, exp = NULL, obs = NULL, sdates, nmember = NULL, } if (length(nmemberobs) != length(obs)) { stop("Error: 'nmemberobs' must contain as many values as 'obs'.") - } else if (any(is.na(nmemberobs))) { + } else if (anyNA(nmemberobs)) { nmemberobs[which(is.na(nmemberobs))] <- max(nmemberobs, na.rm = TRUE) } } @@ -1532,7 +1532,7 @@ Load <- function(var, exp = NULL, obs = NULL, sdates, nmember = NULL, } dims <- dim_exp[na.omit(match(c('dataset', 'member', 'sdate', 'ftime', 'lat', 'lon'), names(dim_exp)))] - if (is.null(dims[['member']]) || any(is.na(unlist(dims))) || any(unlist(dims) == 0)) { + if (is.null(dims[['member']]) || anyNA(unlist(dims)) || any(unlist(dims) == 0)) { dims <- 0 dim_exp <- NULL } @@ -1844,7 +1844,7 @@ Load <- function(var, exp = NULL, obs = NULL, sdates, nmember = NULL, .warning("no data found in file system for any observational dataset.") } dims <- dim_obs[na.omit(match(c('dataset', 'member', 'sdate', 'ftime', 'lat', 'lon'), names(dim_obs)))] - if (is.null(dims[['member']]) || any(is.na(unlist(dims))) || any(unlist(dims) == 0)) { + if (is.null(dims[['member']]) || anyNA(unlist(dims)) || any(unlist(dims) == 0)) { dims <- 0 dim_obs <- NULL } @@ -1864,12 +1864,12 @@ Load <- function(var, exp = NULL, obs = NULL, sdates, nmember = NULL, # So [1, 1, 1, 1, 1, 1] will be next to [2, 1, 1, 1, 1, 1] in memory pointer_var_exp <- pointer_var_obs <- NULL if (!is.null(dim_exp) && (length(unlist(dim_exp)) == length(dim_exp)) && - !any(is.na(unlist(dim_exp))) && !any(unlist(dim_exp) == 0)) { + !anyNA(unlist(dim_exp)) && !any(unlist(dim_exp) == 0)) { var_exp <- big.matrix(nrow = prod(unlist(dim_exp)), ncol = 1) pointer_var_exp <- describe(var_exp) } if (!is.null(dim_obs) && (length(unlist(dim_obs)) == length(dim_obs)) && - !any(is.na(unlist(dim_obs))) && !any(unlist(dim_obs) == 0)) { + !anyNA(unlist(dim_obs)) && !any(unlist(dim_obs) == 0)) { var_obs <- big.matrix(nrow = prod(unlist(dim_obs)), ncol = 1) pointer_var_obs <- describe(var_obs) } diff --git a/R/Utils.R b/R/Utils.R index 76ef63a..1f39694 100644 --- a/R/Utils.R +++ b/R/Utils.R @@ -255,7 +255,7 @@ NA } result <- FALSE - if (!any(is.na(c(nlons, nlats)))) { + if (!anyNA(c(nlons, nlats))) { if ((nlons == length(lon)) && (nlats == length(lat))) { result <- TRUE @@ -583,7 +583,7 @@ } if (length(expected_dims) > 0) { dim_matches <- match(expected_dims, var_dimnames) - if (any(is.na(dim_matches))) { + if (anyNA(dim_matches)) { if (!is.null(old_members_dimname)) { expected_dims[which(expected_dims == 'lev')] <- old_members_dimname } diff --git a/man/Cluster.Rd b/man/Cluster.Rd index 7ea25de..8c46b3d 100644 --- a/man/Cluster.Rd +++ b/man/Cluster.Rd @@ -63,7 +63,7 @@ A list containing: are same as 'data' without 'space_dim'. } \item{$centers}{ - A nemeric array of cluster centres or centroids (e.g. [1:K, 1:spatial degrees + A numeric array of cluster centres or centroids (e.g. [1:K, 1:spatial degrees of freedom]). The rest dimensions are same as 'data' except 'time_dim' and 'space_dim'. } -- GitLab