RMS() error when dat_dim is NULL and conf is FALSE
Hi @aho,
I have found an error in RMS() function related with dat_dim
development. The error is the following:
exp3 <- array(rnorm(120), dim = c(sdate = 5, ftime = 2, lon = 1, lat = 4))
obs3 <- array(rnorm(80), dim = c(sdate = 5, ftime = 2, lon = 1, lat = 4))
> RMS(exp3, obs3, dat_dim = NULL, conf = FALSE)
"Error in dim(conf.lower) <- NULL : object 'conf.lower' not found"
It is because in the atomic function values conf.lower
and conf.upper
are only defined when conf = TRUE
.
if (conf) {
conflow <- (1 - conf.lev) / 2
confhigh <- 1 - conflow
conf.lower <- array(dim = c(nexp = nexp, nobs = nobs))
conf.upper <- array(dim = c(nexp = nexp, nobs = nobs))
}
But then, they are used when dat_dim = NULL
even if conf = FALSE
.
###################################
# Remove nexp and nobs if dat_dim = NULL
if (is.null(dat_dim)) {
dim(rms) <- NULL
dim(conf.lower) <- NULL
dim(conf.upper) <- NULL
}
I have corrected the function in this commit by adding a condition for conf
. Also, I have added a test for this case in test-RMS(). The changes can be found in this merge request.
# Remove nexp and nobs if dat_dim = NULL
if (is.null(dat_dim)) {
dim(rms) <- NULL
if (conf) {
dim(conf.lower) <- NULL
dim(conf.upper) <- NULL
}
}
I am sorry because I developed this function and I didn't notice this error.
Best,
Eva