Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated base/utils #2758 #2773

Merged
merged 11 commits into from
Mar 10, 2021
24 changes: 12 additions & 12 deletions base/utils/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
##' @return ncvar based on MstMIP definition
##' @author Rob Kooper
mstmipvar <- function(name, lat = NA, lon = NA, time = NA, nsoil = NA, silent = FALSE) {
nc_var <- PEcAn.utils::mstmip_vars[PEcAn.utils::mstmip_vars$Variable.Name == name, ]
nc_var <- PEcAn.utils::mstmip_vars[PEcAn.utils::mstmip_vars$Variable.Name == name, ]
infotroph marked this conversation as resolved.
Show resolved Hide resolved
dims <- list()

if (nrow(nc_var) == 0) {
Expand Down Expand Up @@ -207,21 +207,21 @@ zero.bounded.density <- function(x, bw = "SJ", n = 1001) {
##' @author David LeBauer, Alexey Shiklomanov
summarize.result <- function(result) {
ans1 <- result %>%
dplyr::filter(n == 1) %>%
dplyr::filter(.data$n == 1) %>%
dplyr::group_by(.data$citation_id, .data$site_id, .data$trt_id,
.data$control, .data$greenhouse, .data$date, .data$time,
.data$cultivar_id, .data$specie_id, .data$name, .data$treatment_id) %>%
dplyr::summarize( # stat must be computed first, before n and mean
statname = dplyr::if_else(length(n) == 1, "none", "SE"),
stat = stats::sd(mean) / sqrt(length(n)),
n = length(n),
statname = dplyr::if_else(length(.data$n) == 1, "none", "SE"),
stat = stats::sd(.data$mean) / sqrt(length(.data$n)),
n = length(.data$n),
mean = mean(mean)
) %>%
dplyr::ungroup()
ans2 <- result %>%
dplyr::filter(n != 1) %>%
dplyr::filter(.data$n != 1) %>%
# ANS: Silence factor to character conversion warning
dplyr::mutate(statname = as.character(statname))
dplyr::mutate(statname = as.character(.data$statname))
if (nrow(ans2) > 0) {
dplyr::bind_rows(ans1, ans2)
} else {
Expand Down Expand Up @@ -684,25 +684,25 @@ download.file <- function(url, filename, method) {

#--------------------------------------------------------------------------------------------------#
##' Retry function X times before stopping in error
##'
##'
##' @title retry.func
##' @name retry.func
##' @description Retry function X times before stopping in error
##'
##' @param expr The function to try running
##' @param maxErrors The number of times to retry the function
##' @param sleep How long to wait before retrying the function call
##'
##'
##' @return retval returns the results of the function call
##'
##'
##' @examples
##' \dontrun{
##' dap <- retry.func(
##' ncdf4::nc_open('https://thredds.daac.ornl.gov/thredds/dodsC/ornldaac/1220/mstmip_driver_global_hd_climate_lwdown_1999_v1.nc4'),
##' maxErrors=10,
##' sleep=2)
##' }
##'
##'
##' @export
##' @author Shawn Serbin <adapted from https://stackoverflow.com/questions/20770497/how-to-retry-a-statement-on-error>
retry.func <- function(expr, isError = function(x) inherits(x, "try-error"), maxErrors = 5, sleep = 0) {
Expand All @@ -715,7 +715,7 @@ retry.func <- function(expr, isError = function(x) inherits(x, "try-error"), max
PEcAn.logger::logger.warn(msg)
stop(msg)
} else {
msg = sprintf("retry: error in attempt %i/%i [[%s]]", attempts, maxErrors,
msg = sprintf("retry: error in attempt %i/%i [[%s]]", attempts, maxErrors,
utils::capture.output(utils::str(retval)))
PEcAn.logger::logger.warn(msg)
#warning(msg)
Expand Down
7 changes: 2 additions & 5 deletions base/utils/tests/Rcheck_reference.log
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Non-standard file/directory found at top level:
* checking foreign function calls ... OK
* checking R code for possible problems ... NOTE
convert.input: no visible binding for global variable ‘settings’
convert.input: no visible binding for global variable ‘id’
convert.input : log_format_df: no visible binding for global variable
infotroph marked this conversation as resolved.
Show resolved Hide resolved
‘.’
get.results: no visible binding for global variable ‘trait.samples’
Expand All @@ -72,8 +71,7 @@ run.write.configs: no visible binding for global variable
run.write.configs: no visible binding for global variable ‘sa.samples’
run.write.configs: no visible binding for global variable
‘ensemble.samples’
summarize.result: no visible binding for global variable ‘n’
summarize.result: no visible binding for global variable ‘statname’

Undefined global functions or variables:
. citation_id control cultivar_id ensemble.samples
get.parameter.samples greenhouse id median n nr runs.samples
Expand Down Expand Up @@ -219,5 +217,4 @@ Status: 5 WARNINGs, 5 NOTEs
See
‘/tmp/Rtmp6InlXl/PEcAn.utils.Rcheck/00check.log’
for details.


s
moki1202 marked this conversation as resolved.
Show resolved Hide resolved