Commit 71ccf0e0 authored by aho's avatar aho
Browse files

Fix if conditional statement that have length > 1

parent bf27dcbe
Pipeline #7462 passed with stage
in 63 minutes and 46 seconds
......@@ -1409,7 +1409,7 @@ Start <- function(..., # dim = indices/selectors,
# Chunk it only if it is defined dim (i.e., list of character with names of depended dim)
if (!(length(dat_selectors[[depending_dim_name]]) == 1 &&
dat_selectors[[depending_dim_name]] %in% c('all', 'first', 'last'))) {
if (sapply(dat_selectors[[depending_dim_name]], is.character)) {
if (any(sapply(dat_selectors[[depending_dim_name]], is.character))) {
dat_selectors[[depending_dim_name]] <-
dat_selectors[[depending_dim_name]][desired_chunk_indices]
}
......
......@@ -566,7 +566,7 @@ generate_vars_to_transform <- function(vars_to_transform, picked_vars, transform
# Turn indices to values for transform_crop_domain
generate_transform_crop_domain_values <- function(transform_crop_domain, picked_vars) {
if (transform_crop_domain == 'all') {
if (any(transform_crop_domain == 'all')) {
transform_crop_domain <- c(picked_vars[1], tail(picked_vars, 1))
} else { # indices()
if (is.list(transform_crop_domain)) {
......
......@@ -126,44 +126,18 @@ as.vector(exp2)
# .. ..$ latitude : num [1:3(1d)] -81 -84.6 -88.2
test_that("3. transform, indices reverse", {
# lat and lon are lists of indices
suppressWarnings(
exp1 <- Start(dat = '/esarchive/exp/ecmwf/system5_m1/monthly_mean/$var$_f6h/$var$_$sdate$.nc',
var = 'tas',
sdate = '20000101',
ensemble = indices(1),
time = indices(1),
latitude = indices(list(30, 1)),
latitude_reorder = Sort(),
longitude = indices(list(1, 40)), # can't reverse. Different meaning
longitude_reorder = CircularSort(0, 360),
transform = CDORemapper,
transform_params = list(grid = 'r100x50',
method = 'con',
crop = c(0, 11, -90, -81)),
transform_vars = c('latitude', 'longitude'),
transform_extra_cells = 8,
synonims = list(latitude = c('lat', 'latitude'),
longitude = c('longitude', 'lon')),
return_vars = list(latitude = NULL,
longitude = NULL,
time = 'sdate'),
retrieve= T)
)
# This test is not valid because it doesn't make sense to use longitude = 40:1. With the automatic "crop" values, the result is not correct.
## lat and lon are vectors of indices
#test_that("3. transform, indices reverse", {
#
## lat and lon are lists of indices
#suppressWarnings(
#exp2 <- Start(dat = '/esarchive/exp/ecmwf/system5_m1/monthly_mean/$var$_f6h/$var$_$sdate$.nc',
#exp1 <- Start(dat = '/esarchive/exp/ecmwf/system5_m1/monthly_mean/$var$_f6h/$var$_$sdate$.nc',
# var = 'tas',
# sdate = '20000101',
# ensemble = indices(1),
# time = indices(1),
# latitude = 30:1,
# latitude = indices(list(30, 1)),
# latitude_reorder = Sort(),
# longitude = 40:1,
# longitude = indices(list(1, 40)), # can't reverse. Different meaning
# longitude_reorder = CircularSort(0, 360),
# transform = CDORemapper,
# transform_params = list(grid = 'r100x50',
......@@ -179,12 +153,38 @@ exp1 <- Start(dat = '/esarchive/exp/ecmwf/system5_m1/monthly_mean/$var$_f6h/$var
# retrieve= T)
#)
#
#expect_equal(
#as.vector(drop(exp1)[, 4:1]),
#as.vector(exp2)
#)
})
## This test is not valid because it doesn't make sense to use longitude = 40:1. With the automatic "crop" values, the result is not correct.
### lat and lon are vectors of indices
##suppressWarnings(
##exp2 <- Start(dat = '/esarchive/exp/ecmwf/system5_m1/monthly_mean/$var$_f6h/$var$_$sdate$.nc',
## var = 'tas',
## sdate = '20000101',
## ensemble = indices(1),
## time = indices(1),
## latitude = 30:1,
## latitude_reorder = Sort(),
## longitude = 40:1,
## longitude_reorder = CircularSort(0, 360),
## transform = CDORemapper,
## transform_params = list(grid = 'r100x50',
## method = 'con',
## crop = c(0, 11, -90, -81)),
## transform_vars = c('latitude', 'longitude'),
## transform_extra_cells = 8,
## synonims = list(latitude = c('lat', 'latitude'),
## longitude = c('longitude', 'lon')),
## return_vars = list(latitude = NULL,
## longitude = NULL,
## time = 'sdate'),
## retrieve= T)
##)
##
##expect_equal(
##as.vector(drop(exp1)[, 4:1]),
##as.vector(exp2)
##)
#
#})
################################################################
################################################################
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment