FRBCesab / funbiogeo

:package: R package to help with analyses in functional biogeography
https://frbcesab.github.io/funbiogeo/
GNU General Public License v2.0
10 stars 1 forks source link

Kevdev #17

Closed KevCaz closed 2 years ago

KevCaz commented 3 years ago

I introduce stop_condition() function to reduce code redundancy, it replaced the following code chunk that is used frequently

if (cond) {
 stop(paste0("msg", "msg"), call. = FALSE)
}

I thought it would be easier to wrap this in a function, so we can easily change the way we do our stop messages, e.g. to customize the console message (color, icons, etc). So far I've only changed the code in R/checks.R.

codecov-commenter commented 3 years ago

Codecov Report

Merging #17 (1bc7d50) into main (5742681) will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main       #17   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           11        12    +1     
  Lines          388       393    +5     
=========================================
+ Hits           388       393    +5     
Impacted Files Coverage Δ
R/checks.R 100.00% <100.00%> (ø)
R/fb_format_sites_locations.R 100.00% <100.00%> (ø)
R/zzz.R 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update e3122d3...1bc7d50. Read the comment docs.

ahasverus commented 3 years ago

Damn! I am currently working on the same functions but quite differently. For instance, I have written this kind of functions:

is_of_class <- function(x, y) {

  if (!inherits(x, y)) {
    stop("Argument '", deparse(substitute(x)), "' must be of class '",
         paste0(y, collapse = ", "), "'", call. = FALSE)
  }

  invisible(NULL)
}

and,

has_na <- function(x) {
  if (any(is.na(x))) {
    stop("Argument '", deparse(substitute(x)), "' cannot contain NA",
         call. = FALSE)
  } 

  invisible(NULL)
}
ahasverus commented 2 years ago

Thx for this contribution, but we changed the code and this PR is no more needed.