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
22 changes: 11 additions & 11 deletions base/utils/R/utils.R
Original file line number Diff line number Diff line change
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
5 changes: 1 addition & 4 deletions base/utils/tests/Rcheck_reference.log
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,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 +218,3 @@ Status: 5 WARNINGs, 5 NOTEs
See
‘/tmp/Rtmp6InlXl/PEcAn.utils.Rcheck/00check.log’
for details.