diff --git a/R/Corr.R b/R/Corr.R index 10858c29494a38681c96381946144e228fd46101..4654db2ced466e1ff53be85824cf9f0c4b5725bc 100644 --- a/R/Corr.R +++ b/R/Corr.R @@ -149,8 +149,8 @@ Corr <- function(var_exp, var_obs, posloop = 1, poscor = 2, compROW = NULL, } } if (pval && (method == "pearson")) { - t <- CORR * sqrt((eno - 2) / (1 - (CORR ^ 2))) - p_val <- 1 - pt(t, eno - 2) + t <-sqrt(CORR * CORR * (eno - 2) / (1 - (CORR ^ 2))) + p_val <- pt(t, eno - 2, lower.tail = FALSE) } if (conf && (method == "pearson")) { conf_low <- (1 - siglev) / 2 diff --git a/R/Load.R b/R/Load.R index 96b696a8d28b1830922e41c818eb8624a671aea5..190872f334b4b54d85efc88d05813ea7c7d549fa 100644 --- a/R/Load.R +++ b/R/Load.R @@ -268,14 +268,19 @@ Load <- function(var, exp = NULL, obs = NULL, sdates, nmember = NULL, # grid if (!is.null(grid)) { if (is.character(grid)) { - supported_grids <- list('r[0-9]{1,}x[0-9]{1,}', 't[0-9]{1,}grid') - grid_matches <- unlist(lapply(lapply(supported_grids, regexpr, grid), .IsFullMatch, grid)) - if (sum(grid_matches) < 1) { - stop("The specified grid in the parameter 'grid' is incorrect. Must be one of rx or tgrid.") + if (grid == 'none') { + grid <- NULL + } else { + supported_grids <- list('r[0-9]{1,}x[0-9]{1,}', 't[0-9]{1,}grid') + grid_matches <- unlist(lapply(lapply(supported_grids, regexpr, grid), .IsFullMatch, grid)) + if (sum(grid_matches) < 1) { + stop("The specified grid in the parameter 'grid' is incorrect. Must be one of rx or tgrid.") + } } } else { stop("Error: parameter 'grid' should be a character string, if specified.") } + } } # maskmod diff --git a/R/PlotLayout.R b/R/PlotLayout.R index a3f67e56e3c54ae42103cd6a7ac763afdda76ad5..7d5eee1efc2d184e50bb535ba4088fcf9b736c65 100644 --- a/R/PlotLayout.R +++ b/R/PlotLayout.R @@ -432,8 +432,13 @@ PlotLayout <- function(fun, plot_dims, var, ..., special_args = NULL, } plot_number <<- plot_number + 1 } else { + if (is.character(plot_dims[[array_number]])) { + plot_dim_indices <- which(names(dim(x)) %in% plot_dims[[array_number]]) + } else { + plot_dim_indices <- plot_dims[[array_number]] + } # For each of the arrays provided in that array - apply(x, (1:length(dim(x)))[1:(length(dim(x)) - length(plot_dims[[array_number]]))], + apply(x, (1:length(dim(x)))[-plot_dim_indices], function(y) { # Do the plot fun_args <- c(list(y, toptitle = titles[plot_number]), list(...), diff --git a/R/Utils.R b/R/Utils.R index ec1541532f0aa9720930ab5a326d739ce73d3e72..c748a50876375c615c7b8d7c8a387475bc727614 100644 --- a/R/Utils.R +++ b/R/Utils.R @@ -220,6 +220,9 @@ # Here we read the grid type and its number of longitudes and latitudes file_info <- system(paste('cdo -s griddes', filein, '2> /dev/null'), intern = TRUE) grids_positions <- grep('# gridID', file_info) + if (length(grids_positions) < 1) { + stop("The grid should be defined in the files.") + } grids_first_lines <- grids_positions + 2 grids_last_lines <- c((grids_positions - 2)[-1], length(file_info)) grids_info <- as.list(1:length(grids_positions)) @@ -239,12 +242,14 @@ } else { NA } - if ((nlons == length(lon)) && - (nlats == length(lat))) { - TRUE - } else { - FALSE + result <- FALSE + if (!any(is.na(c(nlons, nlats)))) { + if ((nlons == length(lon)) && + (nlats == length(lat))) { + result <- TRUE + } } + result })) grids_matches <- grids_matches[which(grids_types %in% c('gaussian', 'lonlat'))] grids_info <- grids_info[which(grids_types %in% c('gaussian', 'lonlat'))] @@ -261,8 +266,10 @@ } else { stop("Error: Load() can't disambiguate: More than one lonlat/gaussian grids with the same size as the requested variable defined in ", filename) } - } else { + } else if (sum(grids_matches) == 1) { grid_type <- grids_types[which(grids_matches)] + } else { + stop("Unexpected error.") } grid_lons <- length(lon) grid_lats <- length(lat)