Skip to content

Commit

Permalink
Merge pull request #2815 from moki1202/patch-14
Browse files Browse the repository at this point in the history
Fix remaining check warnings from PEcAn.logger (fixes #2814)
  • Loading branch information
mdietze committed Jul 21, 2021
2 parents c2377c1 + dd5644e commit 17c10bc
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 165 deletions.
16 changes: 10 additions & 6 deletions base/logger/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
Package: PEcAn.logger
Title: Logger functions for PEcAn
Title: Logger Functions for PEcAn
Version: 1.7.1
Date: 2019-09-05
Authors@R: c(person("Rob","Kooper"),
person("Alexey", "Shiklomanov"))
Author: Rob Kooper, Alexey Shiklomanov
Maintainer: Alexey Shiklomanov <ashiklom@bu.edu>
Authors@R: c(person("Rob", "Kooper", role = c("aut", "cre"),
email = "kooper@illinois.edu"),
person("Alexey", "Shiklomanov", role = c("aut"),
email = "ashiklom@bu.edu"),
person("Shashank", "Singh", role = c("aut"),
email = "shashanksingh819@gmail.com"),
person("Chris", "Black", role = c("ctb")))
Description: Special logger functions for tracking execution status and the environment.
BugReports: https://github.com/PecanProject/pecan/issues
Imports: utils
Suggests: testthat
License: BSD_3_clause + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.0.2
Roxygen: list(markdown = TRUE)
9 changes: 9 additions & 0 deletions base/logger/NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# PEcAn.logger 1.7.1.9000
## Fixed

* Logger calls no longer create a stray `dump.log` object in the global environment

#PEcAn.logger 1.7.1

* All changes in 1.7.1 and earlier were recorded in a single file for all of the PEcAn packages; please see
https://github.com/PecanProject/pecan/blob/v1.7.1/CHANGELOG.md for details.
30 changes: 13 additions & 17 deletions base/logger/R/logger.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ logger.error <- function(msg, ...) {
##' Prints an severe message and stops execution.
##'
##' This function will print a message and stop execution of the code. This
##' should only be used if the application should terminate.
##' should only be used if the application should terminate.
##'
##' set \code{\link{logger.setQuitOnSevere(FALSE)}}. To avoid terminating
##' set \code{\link{logger.setQuitOnSevere}(FALSE)} to avoid terminating
##' the session. This is set by default to TRUE if interactive or running
##' inside Rstudio.
##'
Expand Down Expand Up @@ -140,11 +140,10 @@ logger.severe <- function(msg, ..., wrap = TRUE) {
##' }
logger.message <- function(level, msg, ..., wrap = TRUE) {
if (logger.getLevelNumber(level) >= .utils.logger$level) {
dump.frames(dumpto = "dump.log")
calls <- names(dump.log)
calls <- utils::limitedLabels(sys.calls())
calls <- calls[!grepl("^(#[0-9]+: )?(PEcAn\\.logger::)?logger", calls)]
calls <- calls[!grepl("(severe|error|warn|info|debug)ifnot", calls)]
func <- sub("\\(.*", "", tail(calls, 1))
func <- sub("\\(.*", "", utils::tail(calls, 1))
if (length(func) == 0) {
func <- "console"
}
Expand Down Expand Up @@ -191,18 +190,15 @@ logger.setLevel <- function(level) {
} # logger.setLevel


##' Returns numeric value for string
##'
##' Given the string representation this will return the numeric value
##' ALL = 0
##' DEBUG = 10
##' INFO = 20
##' WARN = 30
##' ERROR = 40
##' ALL = 99
##'
##' @return level the level of the message
##' @author Rob Kooper
## Given the string representation this will return the numeric value
## DEBUG = 10
## INFO = 20
## WARN = 30
## ERROR = 40
## ALL = 99
##
##@return level the level of the message
##@author Rob Kooper
logger.getLevelNumber <- function(level) {
if (toupper(level) == "ALL") {
return(0)
Expand Down
16 changes: 9 additions & 7 deletions base/logger/R/logifnot.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#' Logger message if conditions are not met
#'
#' Similar to [base::stopifnot], but allows you to use a custom message and
#' Similar to [base::stopifnot], but allows you to use a custom message and
#' logger level. If all conditions are `TRUE`, silently exit.
#'
#' Conditions can be vectorized, or can return non-logical values.The
#' underlying function automatically applies `isTRUE(all(.))` to the
#' Conditions can be vectorized, or can return non-logical values.The
#' underlying function automatically applies `isTRUE(all(.))` to the
#' conditions.
#'
#' @param msg Logger message to write, as a single character string.
#' @param ... Conditions to evaluate
#' @param ... Conditions to evaluate
#' @return Invisibly, `TRUE` if conditions are met, `FALSE` otherwise
#' @examples
#' a <- 1:5
Expand All @@ -18,7 +18,9 @@
#' warnifnot("I would prefer it if you used lists.", is.list(a), is.list(b))
#' errorifnot("You should definitely use lists.", is.list(a), is.list(b))
#' try({
#' severeifnot("I absolutely cannot deal with the fact that something is not a list.", is.list(a), is.list(b))
#' severeifnot("I cannot deal with the fact that something is not a list.",
#' is.list(a),
#' is.list(b))
#' })
#' @export
severeifnot <- function(msg, ...) {
Expand Down Expand Up @@ -73,14 +75,14 @@ debugifnot <- function(msg, ...) {
}
}

#' Check a list of conditions
# Check a list of conditions
check_conditions <- function(...) {
dots <- list(...)
conditions <- vapply(dots, is_definitely_true, logical(1))
all(conditions)
}

#' Robust logical check
# Robust logical check
is_definitely_true <- function(x) {
if (is.null(x) || length(x) == 0 || !is.logical(x)) {
return(FALSE)
Expand Down
2 changes: 1 addition & 1 deletion base/logger/R/print2string.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
#' logger.debug("Current status:\n", print2string(df, row.names = FALSE), wrap = FALSE)
#' @export
print2string <- function(x, ...) {
cout <- capture.output(print(x, ...))
cout <- utils::capture.output(print(x, ...))
paste(cout, collapse = "\n")
}
11 changes: 0 additions & 11 deletions base/logger/man/check_conditions.Rd

This file was deleted.

11 changes: 0 additions & 11 deletions base/logger/man/is_definitely_true.Rd

This file was deleted.

23 changes: 0 additions & 23 deletions base/logger/man/logger.getLevelNumber.Rd

This file was deleted.

2 changes: 1 addition & 1 deletion base/logger/man/logger.severe.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion base/logger/man/severeifnot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 0 additions & 87 deletions base/logger/tests/Rcheck_reference.log

This file was deleted.

0 comments on commit 17c10bc

Please sign in to comment.