Skip to content

Commit

Permalink
styler
Browse files Browse the repository at this point in the history
  • Loading branch information
joethorley committed Oct 5, 2023
1 parent 97d5aaf commit 1537db1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion R/chk-length.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ chk_length <- function(x, length = 1L, upper = length, x_name = NULL) {
return(invisible(x))
}
if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x))
if(length == upper) {
if (length == upper) {
abort_chk(x_name, " must be length ", length, " not ", length(x), x = x, length = length)
}
abort_chk(x_name, " must have a length between ", length, " and ", upper, " not ", length(x), x = x, length = length)
Expand Down
7 changes: 4 additions & 3 deletions R/chk-range.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ chk_range <- function(x, range = c(0, 1), inclusive = TRUE, x_name = NULL) {
abort_chk(x_name, " must have values of ", cc(range[1]), x = x, range = range)
}
abort_chk(x_name, " must have values between ", cc(range, " and "),
ifelse(isTRUE(inclusive), "", " exclusive"),
x = x, range = range)
ifelse(isTRUE(inclusive), "", " exclusive"),
x = x, range = range
)
}

#' @describeIn chk_range Validate Range
Expand All @@ -57,7 +58,7 @@ chk_range <- function(x, range = c(0, 1), inclusive = TRUE, x_name = NULL) {
#' vld_range(c(0.1, 0.2, NA), range = c(0, 1))
#' @export
vld_range <- function(x, range = c(0, 1), inclusive = TRUE) {
if(isTRUE(inclusive)) {
if (isTRUE(inclusive)) {
return(all(x[!is.na(x)] >= range[1] & x[!is.na(x)] <= range[2]))
}
all(x[!is.na(x)] > range[1] & x[!is.na(x)] < range[2])
Expand Down
6 changes: 3 additions & 3 deletions R/err.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ NULL
#' # err
#' try(err("there %r %n problem value%s", n = 2))
err <- function(..., n = NULL, tidy = TRUE, .subclass = NULL, class = NULL, call = rlang::caller_call(3)) {
if(!is.null(.subclass)) {
if (!is.null(.subclass)) {
deprecate_soft("0.8.1", "err(.subclass)", "err(class)")
class <- .subclass
}
Expand Down Expand Up @@ -104,7 +104,7 @@ err <- function(..., n = NULL, tidy = TRUE, .subclass = NULL, class = NULL, call
#' # wrn
#' wrn("there %r %n problem value%s", n = 2)
wrn <- function(..., n = NULL, tidy = TRUE, .subclass = NULL, class = NULL) {
if(!is.null(.subclass)) {
if (!is.null(.subclass)) {
deprecate_soft("0.8.1", "wrn(.subclass)", "wrn(class)")
class <- .subclass
}
Expand All @@ -120,7 +120,7 @@ wrn <- function(..., n = NULL, tidy = TRUE, .subclass = NULL, class = NULL) {
#' # msg
#' msg("there %r %n problem value%s", n = 2)
msg <- function(..., n = NULL, tidy = TRUE, .subclass = NULL, class = NULL) {
if(!is.null(.subclass)) {
if (!is.null(.subclass)) {
deprecate_soft("0.8.1", "msg(.subclass)", "msg(class)")
class <- .subclass
}
Expand Down
8 changes: 5 additions & 3 deletions scripts/build.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
roxygen2md::roxygen2md()
styler::style_pkg(filetype = c("R", "Rmd"))
styler::style_pkg(
scope = "line_breaks",
filetype = c("R", "Rmd")
)
lintr::lint_package()

devtools::test()
devtools::document()

rmarkdown::render("README.Rmd", output_format = "md_document")
pkgdown::build_site()
pkgdown::build_home()

devtools::check()
7 changes: 4 additions & 3 deletions tests/testthat/test-chk-null-or.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ test_that("chk_null_or gives correct error message", {
rlang::local_options(lifecycle_verbosity = "quiet")
expect_error(
chk_null_or("2000", vld = vld_whole_number),
"^`\"2000\"` must be a whole number \\(non-missing integer scalar or double equivalent\\) or NULL\\.$")
"^`\"2000\"` must be a whole number \\(non-missing integer scalar or double equivalent\\) or NULL\\.$"
)
expect_error(
chk_null_or("2000", vld = chk::vld_whole_number),
"^`\"2000\"` must be a whole number \\(non-missing integer scalar or double equivalent\\) or NULL\\.$")
"^`\"2000\"` must be a whole number \\(non-missing integer scalar or double equivalent\\) or NULL\\.$"
)
})

0 comments on commit 1537db1

Please sign in to comment.