diff --git a/R/CST_QuantileMapping.R b/R/CST_QuantileMapping.R index 6682e7aa65b84c0a60cbe149f00b9ec995d25a4c..d8e2ec7339fc3604d0eb645d462c65e5dde3cf07 100644 --- a/R/CST_QuantileMapping.R +++ b/R/CST_QuantileMapping.R @@ -103,10 +103,10 @@ QuantileMapping <- function(exp, obs, exp_cor = NULL, sample_dims = 'ftime', stop("Parameter 'obs' must have dimension names.") } if (any(is.na(exp))) { - stop("Parameter 'exp' contains NA values.") + warning("Parameter 'exp' contains NA values.") } if (any(is.na(obs))) { - stop("Parameter 'obs' contains NA values.") + warning("Parameter 'obs' contains NA values.") } if (!is.null(exp_cor)) { exp_cordims <- names(dim(exp_cor)) @@ -326,6 +326,11 @@ qmapcor <- function(exp, obs, exp_cor = NULL, sample_length = NULL, method = 'QU } applied <- c(applied, doQmap(x = sample_cor, fobj = adjust, ...)) } + if (any(is.na(exp_cor))) { + pos <- which(!is.na(exp_cor)) + exp_cor[pos] <- applied + applied <- exp_cor + } dim(applied) <- dimensions return(applied) } diff --git a/R/CST_SplitDim.R b/R/CST_SplitDim.R index ce65e07f5c293920462dbb0e393346644cb0c481..46cd97cca21aeb1787b6d572f30662fdffb4181e 100644 --- a/R/CST_SplitDim.R +++ b/R/CST_SplitDim.R @@ -50,7 +50,7 @@ CST_SplitDim <- function(data, split_dim = 'time', indices = NULL, stop("Parameter 'split_dims' must be one of the dimension ", "names in parameter 'data'.") } - indices <- indices[1 : dim(data$data)[which(names(dim(data$data)) == + indices <- indices[1 : dim(data$data)[which(names(dim(data$data)) == split_dim)]] } } diff --git a/tests/testthat/test-CST_QuantileMapping.R b/tests/testthat/test-CST_QuantileMapping.R index 4a317b5a58abfee986448c10a0fcfbb215ee7224..9a9554471850cb65c6cc6185c9931529e7b7b996 100644 --- a/tests/testthat/test-CST_QuantileMapping.R +++ b/tests/testthat/test-CST_QuantileMapping.R @@ -72,13 +72,13 @@ library(qmap) "length of the timeseries will be used.") exp$data[1] <- NA - expect_error( + expect_warning( CST_QuantileMapping(exp = exp, obs = obs, sample_dims = 'time'), "Parameter 'exp' contains NA values.") exp$data[1] <- 1 obs$data[1] <- NA - expect_error( + expect_warning( CST_QuantileMapping(exp = exp, obs = obs, sample_dims = 'time'), "Parameter 'obs' contains NA values.") obs$data[1] <- 1