diff --git a/R/AbsToProbs.R b/R/AbsToProbs.R index ce5f01ae9f5a3eb3ce0bf20fb18c891656f9600e..89c72c929ad34477e787b5099ea4e2f125998b92 100644 --- a/R/AbsToProbs.R +++ b/R/AbsToProbs.R @@ -58,13 +58,13 @@ CST_AbsToProbs <- function(data, start = NULL, end = NULL, if (is.null(dim(data$Dates$start))) { if (length(data$Dates$start) != dim(data$data)[time_dim]) { if (length(data$Dates$start) == - prod(dim(data$data)[time_dim] * dim(data$data)['sdate'])) { + prod(dim(data$data)[time_dim] * dim(data$data)[sdate_dim])) { dim(data$Dates$start) <- c(dim(data$data)[time_dim], - dim(data$data)['sdate']) + dim(data$data)[sdate_dim]) + } else { + warning("Dimensions in 'data' element 'Dates$start' are missed and ", + "all data would be used.") } - } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", - "all data would be used.") } } } diff --git a/R/AccumulationExceedingThreshold.R b/R/AccumulationExceedingThreshold.R index 62a4bc44a08bab8e7030cdb74f7115dfb79fce76..62845bab8834e04328b038758660c62af19cf4dc 100644 --- a/R/AccumulationExceedingThreshold.R +++ b/R/AccumulationExceedingThreshold.R @@ -60,17 +60,17 @@ CST_AccumulationExceedingThreshold <- function(data, threshold, op = '>', if (!is.null(start) && !is.null(end)) { if (is.null(dim(data$Dates$start))) { if (length(data$Dates$start) != dim(data$data)[time_dim]) { - if (length(data$Dates$start) == + if (length(data$Dates$start) == prod(dim(data$data)[time_dim] * dim(data$data)['sdate'])) { dim(data$Dates$start) <- c(dim(data$data)[time_dim], dim(data$data)['sdate']) + } else { + warning("Dimensions in 'data' element 'Dates$start' are missed and ", + "all data would be used.") } - } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", - "all data would be used.") } } - } + } if (inherits(threshold, 's2dv_cube')) { threshold <- threshold$data } diff --git a/R/MergeRefToExp.R b/R/MergeRefToExp.R index 837d3045817b71226c9d0ade96e921bf274812bf..068acfe00c7fabfdeae621da2918922f58103da5 100644 --- a/R/MergeRefToExp.R +++ b/R/MergeRefToExp.R @@ -77,11 +77,11 @@ CST_MergeRefToExp <- function(data1, data2, start1, end1, start2, end2, if (length(data1$Dates$start) == prod(dim(data1$data)[time_dim] * dim(data1$data)['sdate'])) { dim(data1$Dates$start) <- c(dim(data1$data)[time_dim], - dim(data1$data)['sdate']) + dim(data1$data)['sdate']) + } else { + warning("Dimensions in 'data' element 'data$Dates$start' are missed and", + "all data would be used.") } - } else { - warning("Dimensions in 'data' element 'data$Dates$start' are missed and", - "all data would be used.") } } # when subsetting is needed, dimensions are also needed: @@ -91,10 +91,10 @@ CST_MergeRefToExp <- function(data1, data2, start1, end1, start2, end2, prod(dim(data2$data)[time_dim] * dim(data2$data)['sdate'])) { dim(data2$Dates$start) <- c(dim(data2$data)[time_dim], dim(data2$data)['sdate']) + } else { + warning("Dimensions in 'data' element 'data$Dates$start' are missed and ", + "all data would be used.") } - } else { - warning("Dimensions in 'data' element 'data$Dates$start' are missed and", - "all data would be used.") } } data1$data <- MergeRefToExp(data1 = data1$data, dates1 = data1$Dates[[1]], diff --git a/R/PeriodAccumulation.R b/R/PeriodAccumulation.R index 92ec947dcca7966fad696b73110a63a277efb908..5a672e05aa4a041e5eb29696845eb1dfd460eec7 100644 --- a/R/PeriodAccumulation.R +++ b/R/PeriodAccumulation.R @@ -68,10 +68,10 @@ CST_PeriodAccumulation <- function(data, start = NULL, end = NULL, prod(dim(data$data)[time_dim] * dim(data$data)['sdate'])) { dim(data$Dates$start) <- c(dim(data$data)[time_dim], dim(data$data)['sdate']) + } else { + warning("Dimensions in 'data' element 'Dates$start' are missed and ", + "all data would be used.") } - } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", - "all data would be used.") } } } diff --git a/R/PeriodMean.R b/R/PeriodMean.R index c75cee3f09826fc8c497cdbe9685792c818483b8..73700fd21fc21acbddef006443c4dfbf013c9e6f 100644 --- a/R/PeriodMean.R +++ b/R/PeriodMean.R @@ -56,9 +56,9 @@ CST_PeriodMean <- function(data, start = NULL, end = NULL, prod(dim(data$data)[time_dim] * dim(data$data)['sdate'])) { dim(data$Dates$start) <- c(dim(data$data)[time_dim], dim(data$data)['sdate']) + } else { + warning("Dimensions in 'data' element 'Dates$start' are missed/unmatched. All data would be used.") } - } else { - warning("Dimensions in 'data' element 'Dates$start' are missed/unmatched. All data would be used.") } } } diff --git a/R/QThreshold.R b/R/QThreshold.R index 6b4359d13fbfdffe4b9ee7997fcbac82db90413f..46634113f818ae3de7dd37e29db8c2627e323288 100644 --- a/R/QThreshold.R +++ b/R/QThreshold.R @@ -80,13 +80,13 @@ CST_QThreshold <- function(data, threshold, start = NULL, end = NULL, if (is.null(dim(data$Dates$start))) { if (length(data$Dates$start) != dim(data$data)[time_dim]) { if (length(data$Dates$start) == - prod(dim(data$data)[time_dim] * dim(data$data)['sdate'])) { + prod(dim(data$data)[time_dim] * dim(data$data)[sdate_dim])) { dim(data$Dates$start) <- c(dim(data$data)[time_dim], - dim(data$data)['sdate']) + dim(data$data)[sdate_dim]) + } else { + warning("Dimensions in 'data' element 'Dates$start' are missed and ", + "all data would be used.") } - } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", - "all data would be used.") } } } diff --git a/R/SelectPeriodOnData.R b/R/SelectPeriodOnData.R index f15c60e1095228ccb98fdcd4c34195f0006eb067..49575a2d9bf4361b3a14647a290815055f76711c 100644 --- a/R/SelectPeriodOnData.R +++ b/R/SelectPeriodOnData.R @@ -47,10 +47,10 @@ CST_SelectPeriodOnData <- function(data, start, end, time_dim = 'ftime', ncores prod(dim(data$data)[time_dim] * dim(data$data)['sdate'])) { dim(data$Dates$start) <- c(dim(data$data)[time_dim], dim(data$data)['sdate']) + } else { + warning("Dimensions in 'data' element 'Dates$start' are missed and ", + "all data would be used.") } - } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", - "all data would be used.") } } } diff --git a/R/Threshold.R b/R/Threshold.R index 755c2e603ed0136266502dfe7f7bdcd2a529299f..18b8dea19f1f546afa57a6cc4abe630a76bdd08e 100644 --- a/R/Threshold.R +++ b/R/Threshold.R @@ -64,13 +64,13 @@ CST_Threshold <- function(data, threshold, start = NULL, end = NULL, if (is.null(dim(data$Dates$start))) { if (length(data$Dates$start) != dim(data$data)[time_dim]) { if (length(data$Dates$start) == - prod(dim(data$data)[time_dim] * dim(data$data)['sdate'])) { + prod(dim(data$data)[time_dim] * dim(data$data)[sdate_dim])) { dim(data$Dates$start) <- c(dim(data$data)[time_dim], - dim(data$data)['sdate']) + dim(data$data)[sdate_dim]) + } else { + warning("Dimensions in 'data' element 'Dates$start' are missed and ", + "all data would be used.") } - } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", - "all data would be used.") } } } diff --git a/R/TotalSpellTimeExceedingThreshold.R b/R/TotalSpellTimeExceedingThreshold.R index 97981ee0dfe1827906e3faca075b616ff3881613..9a5de435470ea8fba6653f6091a0126648ff4fd8 100644 --- a/R/TotalSpellTimeExceedingThreshold.R +++ b/R/TotalSpellTimeExceedingThreshold.R @@ -68,20 +68,20 @@ CST_TotalSpellTimeExceedingThreshold <- function(data, threshold, spell, op = '> prod(dim(data$data)[time_dim] * dim(data$data)['sdate'])) { dim(data$Dates$start) <- c(dim(data$data)[time_dim], dim(data$data)['sdate']) + } else { + warning("Dimensions in 'data' element 'Dates$start' are missed and ", + "all data would be used.") } - } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", - "all data would be used.") } } - } - if (inherits(threshold, 's2dv_cube')) { + } + if (inherits(threshold, 's2dv_cube')) { threshold <- threshold$data } - total <- TotalSpellTimeExceedingThreshold(data$data, data$Dates[[1]], - threshold = threshold, spell = spell, op = op, - start = start, end = end, time_dim = time_dim, - ncores = ncores) + total <- TotalSpellTimeExceedingThreshold(data$data, data$Dates[[1]], + threshold = threshold, spell = spell, op = op, + start = start, end = end, time_dim = time_dim, + ncores = ncores) data$data <- total if (!is.null(start) && !is.null(end)) { data$Dates <- SelectPeriodOnDates(dates = data$Dates$start, diff --git a/R/TotalTimeExceedingThreshold.R b/R/TotalTimeExceedingThreshold.R index ee0d8ac9a7f7c069153448fb4cc393b07642a2d7..5e800f059535a08130d772ac45f3380ccb27b124 100644 --- a/R/TotalTimeExceedingThreshold.R +++ b/R/TotalTimeExceedingThreshold.R @@ -72,20 +72,20 @@ CST_TotalTimeExceedingThreshold <- function(data, threshold, op = '>', prod(dim(data$data)[time_dim] * dim(data$data)['sdate'])) { dim(data$Dates$start) <- c(dim(data$data)[time_dim], dim(data$data)['sdate']) + } else { + warning("Dimensions in 'data' element 'Dates$start' are missed and ", + "all data would be used.") } - } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", - "all data would be used.") } } - } - if (inherits(threshold, 's2dv_cube')) { + } + if (inherits(threshold, 's2dv_cube')) { threshold <- threshold$data } - total <- TotalTimeExceedingThreshold(data$data, data$Dates[[1]], - threshold = threshold, op = op, - start = start, end = end, time_dim = time_dim, - na.rm = na.rm, ncores = ncores) + total <- TotalTimeExceedingThreshold(data$data, data$Dates[[1]], + threshold = threshold, op = op, + start = start, end = end, time_dim = time_dim, + na.rm = na.rm, ncores = ncores) data$data <- total if (!is.null(start) && !is.null(end)) { data$Dates <- SelectPeriodOnDates(dates = data$Dates$start, diff --git a/R/WindCapacityFactor.R b/R/WindCapacityFactor.R index 61565b03556e91619bcc56f9979e7f0928bf893d..659e6d4c7f06ebfacdab87460cf2682072c73dc0 100644 --- a/R/WindCapacityFactor.R +++ b/R/WindCapacityFactor.R @@ -63,9 +63,10 @@ CST_WindCapacityFactor <- function(wind, IEC_class = c("I", "I/II", "II", "II/II prod(dim(wind$data)[time_dim] * dim(wind$data)['sdate'])) { dim(wind$Dates$start) <- c(dim(wind$data)[time_dim], dim(wind$data)['sdate']) + } else { + warning("Dimensions in 'data' element 'Dates$start' are missed and ", + "all data would be used.") } - } else { - warning("Dimensions in 'data' element 'Dates$start' are missed/unmatched. All data would be used.") } } } diff --git a/R/WindPowerDensity.R b/R/WindPowerDensity.R index 99d5d80e8045bdca543f72e0b8244b89c7ab0dbf..6bbc5978b0bac13e7614c6968af3809f93109ddf 100644 --- a/R/WindPowerDensity.R +++ b/R/WindPowerDensity.R @@ -53,9 +53,10 @@ CST_WindPowerDensity <- function(wind, ro = 1.225, start = NULL, end = NULL, prod(dim(wind$data)[time_dim] * dim(wind$data)['sdate'])) { dim(wind$Dates$start) <- c(dim(wind$data)[time_dim], dim(wind$data)['sdate']) + } else { + warning("Dimensions in 'data' element 'Dates$start' are missed and ", + "all data would be used.") } - } else { - warning("Dimensions in 'wind' element 'Dates$start' are missed/unmatched. All data would be used.") } } } @@ -68,8 +69,8 @@ CST_WindPowerDensity <- function(wind, ro = 1.225, start = NULL, end = NULL, } if (!is.null(start) && !is.null(end)) { wind$Dates <- SelectPeriodOnDates(dates = wind$Dates[[1]], - start = start, end = end, - time_dim = time_dim, ncores = ncores) + start = start, end = end, + time_dim = time_dim, ncores = ncores) } return(wind) } diff --git a/tests/testthat/test-PeriodMean.R b/tests/testthat/test-PeriodMean.R index c9a0a37e40daf7e8dbda589d348f25367d03ac4b..75b6d576550eef3e1aed99a9e025490efbf28b84 100644 --- a/tests/testthat/test-PeriodMean.R +++ b/tests/testthat/test-PeriodMean.R @@ -2,15 +2,21 @@ context("Generic tests") test_that("Sanity Checks", { #source("csindicators/R/PeriodMean.R") expect_error(PeriodMean('x'), "Parameter 'data' must be numeric.") - expect_equal(PeriodMean(array(1, c(x = 1)), time_dim = 'x'), 1) + suppressWarnings( + expect_equal(PeriodMean(array(1, c(x = 1)), time_dim = 'x'), 1) + ) + expect_error(PeriodMean(data = NULL), "Parameter 'data' cannot be NULL.") expect_error(PeriodMean(1, dates = '2000-01-01', end = 3, start = 4), "Parameter 'start' and 'end' must be lists indicating the day and the month of the period start and end.") - - expect_equal(PeriodMean(array(1:10, c(time = 10))), 5.5) + suppressWarnings( + expect_equal(PeriodMean(array(1:10, c(time = 10))), 5.5) + ) data <- array(1:24, c(sdate = 2, time = 3, lon = 4)) - expect_equal(PeriodMean(data), - array(c(3,4,9,10,15,16,21,22), c(sdate = 2, lon = 4))) + suppressWarnings( + expect_equal(PeriodMean(data), + array(c(3,4,9,10,15,16,21,22), c(sdate = 2, lon = 4))) + ) }) test_that("seasonal", {