diff --git a/R/AddStep.R b/R/AddStep.R index 037bd58ca9aae1f11be3042dd046dc488d9ac005..a129f1ef80260a7969ed3cb5f220b1f4b040f31b 100644 --- a/R/AddStep.R +++ b/R/AddStep.R @@ -44,19 +44,18 @@ #'@export AddStep <- function(inputs, step_fun, ...) { # Check step_fun - if (!('startR_step_fun' %in% class(step_fun))) { + if (!is(step_fun, 'startR_step_fun')) { stop("Parameter 'step_fun' must be a startR step function as returned by Step.") } # Check inputs - if (any(c('startR_cube', 'startR_workflow') %in% class(inputs))) { + if (is(inputs, 'startR_cube') | is(inputs, 'startR_workflow')) { inputs <- list(inputs) names(inputs) <- 'input1' } else if (is.list(inputs)) { if (any(!sapply(inputs, - function(x) any(c('startR_cube', - 'startR_workflow') %in% class(x))))) { + function(x) is(x, 'startR_cube') | is(x, 'startR_workflow')))) { stop("Parameter 'inputs' must be one or a list of objects of the class ", "'startR_cube' or 'startR_workflow'.") } @@ -90,7 +89,7 @@ AddStep <- function(inputs, step_fun, ...) { stop("The target dimensions required by 'step_fun' for the input ", input, " are not present in the corresponding provided object in 'inputs'.") } - if ('startR_workflow' %in% class(inputs[[input]])) { + if (is(inputs[[input]], 'startR_workflow')) { if (is.null(previous_target_dims)) { previous_target_dims <- attr(inputs[[input]], 'TargetDims') } else { diff --git a/R/ByChunks.R b/R/ByChunks.R index 8185763bf5c31d388bdb28d5ab3873d8636f46d9..4782ef275557a1988cbd8d21db6d67b2c8d2e1df 100644 --- a/R/ByChunks.R +++ b/R/ByChunks.R @@ -109,7 +109,7 @@ ByChunks <- function(step_fun, cube_headers, ..., chunks = 'auto', MergeArrays <- .MergeArrays # Check input headers - if ('startR_cube' %in% class(cube_headers)) { + if (is(cube_headers, 'startR_cube')) { cube_headers <- list(cube_headers) } if (!all(sapply(lapply(cube_headers, class), @@ -411,7 +411,7 @@ ByChunks <- function(step_fun, cube_headers, ..., chunks = 'auto', timings[['nchunks']] <- prod(unlist(chunks)) # Check step_fun - if (!('startR_step_fun' %in% class(step_fun))) { + if (!is(step_fun, 'startR_step_fun')) { stop("Parameter 'step_fun' must be of the class 'startR_step_fun', as returned ", "by the function Step.") } diff --git a/R/Collect.R b/R/Collect.R index bf387297722c15e61e36d6b768624aec0b73c605..4c80b037d4b91101fc0e90fc6c5c3b1f09b5d624 100644 --- a/R/Collect.R +++ b/R/Collect.R @@ -72,7 +72,7 @@ #' #'@export Collect <- function(startr_exec, wait = TRUE, remove = TRUE) { - if (!('startR_exec' %in% class(startr_exec))) { + if (!is(startr_exec, 'startR_exec')) { stop("Parameter 'startr_exec' must be an object of the class ", "'startR_exec', as returned by Collect(..., wait = FALSE).") } diff --git a/R/Compute.R b/R/Compute.R index 0e8d42cd134a3bbc66fc896a357db1e4f5cd65a5..778d9ced74508a59a1e5512e8d4d93bb2cab45df 100644 --- a/R/Compute.R +++ b/R/Compute.R @@ -89,13 +89,13 @@ Compute <- function(workflow, chunks = 'auto', ecflow_server = NULL, silent = FALSE, debug = FALSE, wait = TRUE) { # Check workflow - if (!any(c('startR_cube', 'startR_workflow') %in% class(workflow))) { + if (!is(workflow, 'startR_cube') & !is(workflow, 'startR_workflow')) { stop("Parameter 'workflow' must be an object of class 'startR_cube' as ", "returned by Start or of class 'startR_workflow' as returned by ", "AddStep.") } - if ('startR_cube' %in% class(workflow)) { + if (is(workflow, 'startR_cube')) { #machine_free_ram <- 1000000000 #max_ram_ratio <- 0.5 #data_size <- prod(c(attr(workflow, 'Dimensions'), 8)) diff --git a/R/SelectorChecker.R b/R/SelectorChecker.R index 81ec4889ff344b808e1b9ab0569a05d893e80aa6..76899c13450b751dc7ef411f6ff11065de0a29a3 100644 --- a/R/SelectorChecker.R +++ b/R/SelectorChecker.R @@ -93,7 +93,7 @@ SelectorChecker <- function(selectors, var = NULL, return_indices = TRUE, tol <- 0 if (!is.null(tolerance)) { - if (!any(class(tolerance) %in% "numeric")) { + if (!is(tolerance, "numeric")) { stop("Expected a numeric *_tolerance.") } tol <- tolerance @@ -148,7 +148,7 @@ SelectorChecker <- function(selectors, var = NULL, return_indices = TRUE, val <- selectors[[i]] tol <- 0 if (!is.null(tolerance)) { - if (!any(class(tolerance) %in% "difftime")) { + if (!is(tolerance, "difftime")) { stop("Expected a difftime *_tolerance.") } tol <- tolerance @@ -194,7 +194,7 @@ SelectorChecker <- function(selectors, var = NULL, return_indices = TRUE, "nearest values.")) } if (!is.null(tolerance)) { - if (!any(class(tolerance) %in% 'numeric')) { + if (!is(tolerance, 'numeric')) { stop("Expected a numeric *_tolerance.") } } @@ -228,7 +228,7 @@ SelectorChecker <- function(selectors, var = NULL, return_indices = TRUE, "nearest values.")) } if (!is.null(tolerance)) { - if (!any(class(tolerance) %in% 'difftime')) { + if (!is(tolerance, 'difftime')) { stop("Expected a difftime *_tolerance.") } } diff --git a/R/Start.R b/R/Start.R index 6fc05ea2d3d8d8c46437adf229040123db1e0f24..f61533603f3ad4f01f1a18ed2361bd7ad0a54ba3 100644 --- a/R/Start.R +++ b/R/Start.R @@ -1384,7 +1384,7 @@ Start <- function(..., # dim = indices/selectors, # names as depended dim. for (j in 1:length(dat_selectors[[file_dim]])) { sv <- selector_vector <- dat_selectors[[file_dim]][[j]] - if (!identical(first_class, class(sv)) || + if (!is(sv, first_class) || !identical(first_length, length(sv))) { stop("All provided selectors for depending dimensions must ", "be vectors of the same length and of the same class.") diff --git a/R/Utils.R b/R/Utils.R index d0e850e7f8c01180ef043ca5d4b5886ea3abca61..425336eff1b4d908a3030cca40bcbfed65d2ee65 100644 --- a/R/Utils.R +++ b/R/Utils.R @@ -806,7 +806,7 @@ readRDS(paste0(shared_dir, '/', chunk_files_original[found_chunk])) }) - if (('try-error' %in% class(array_of_chunks[[i]]))) { + if (is(array_of_chunks[[i]], 'try-error')) { message("Waiting for an incomplete file transfer...") Sys.sleep(5) } else { diff --git a/R/zzz.R b/R/zzz.R index 0067d6d88022615a6c8583fe7d22e79e367aeade..83e2b7b7846e6e7427de58d00477f5152884f107 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1059,7 +1059,7 @@ remove_additional_na_from_merge <- function(data_array = NULL, merge_dim_metadat # data_array can be data or metadata; if data, change the blank spaces from # NA to -9999; if metadata (supposed to be 'time'), change the corresponding # spaces to -12^10. - if (any(class(data_array) %in% c("POSIXct", "POSIXt"))) { + if (is(data_array, "POSIXct")) { # change to numeric first data_array <- array(as.vector(data_array), dim = dim(data_array)) data_array[which(!logi_array)] <- -12^10