Skip to content

Commit

Permalink
Merge pull request #35 from Moohan/lint/fixes
Browse files Browse the repository at this point in the history
Lint/fixes
  • Loading branch information
Moohan authored Jan 11, 2024
2 parents 69d0967 + d507c45 commit 1c25216
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 17 deletions.
3 changes: 2 additions & 1 deletion R/api_key.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ get_api_key <- function() {
return(testing_key())
} else {
cli::cli_abort(
"No API key found, please supply with {.arg api_key} argument or with {.help [{.fun set_api_key}](octopusR::set_api_key)}",
"No API key found, please supply with {.arg api_key} argument or with
{.help [{.fun set_api_key}](octopusR::set_api_key)}",
call = rlang::caller_env()
)
}
Expand Down
15 changes: 8 additions & 7 deletions R/check_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
#'
#' @return NULL
check_datetime_format <- function(arg_date) {
arg <- rlang::caller_arg(arg_date)
call <- rlang::caller_env()
if (!inherits(arg_date, "character") &&
!inherits(arg_date, "Date")) {
if (!inherits(arg_date, "character") && !inherits(arg_date, "Date")) {
cli::cli_abort(
"{.arg {arg}} must be {.cls character} or {.cls Date}, not {.cls {class(arg_date)}}.",
"{.arg {rlang::caller_arg(arg_date)}} must be {.cls character} or
{.cls Date}, not {.cls {class(arg_date)}}.",
call = call
)
}
Expand All @@ -24,7 +23,8 @@ check_datetime_format <- function(arg_date) {
if (!grepl(iso_8601_pattern, arg_date, perl = TRUE)) {
cli::cli_abort(
c(
"{.arg {arg}} must be in [ISO_8601](https://en.wikipedia.org/wiki/ISO_8601) format.",
"{.arg {rlang::caller_arg(arg_date)}} must be in
[ISO_8601](https://en.wikipedia.org/wiki/ISO_8601) format.",
">" = "For example {.val {Sys.Date()}} or {.val {Sys.time()}}."
),
call = call
Expand All @@ -43,10 +43,11 @@ check_datetime_format <- function(arg_date) {
#'
#' @return NULL
check_logical <- function(arg_lgl) {
arg <- rlang::caller_arg(arg_lgl)
call <- rlang::caller_env()
if (!inherits(arg_lgl, "logical")) {
cli::cli_abort("{.arg {arg}} must be {.cls logical}, not {.cls {class(arg_lgl)}}.",
cli::cli_abort(
"{.arg {rlang::caller_arg(arg_lgl)}} must be {.cls logical},
not {.cls {class(arg_lgl)}}.",
call = call
)
}
Expand Down
6 changes: 4 additions & 2 deletions R/get_consumption.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ get_consumption <- function(
force(api_key)
if (!missing(period_to) && missing(period_from)) {
cli::cli_abort(
"To use {.arg period_to} you must also provide the {.arg period_from} parameter to create a range."
"To use {.arg period_to} you must also provide the {.arg period_from}
parameter to create a range."
)
}
if (missing(order_by)) {
Expand All @@ -78,7 +79,8 @@ get_consumption <- function(

if (missing(period_from)) {
cli::cli_abort(
"You must also specify {.arg period_to} when specifying {.arg period_from}."
"You must also specify {.arg period_to} when specifying
{.arg period_from}."
)
}
}
Expand Down
7 changes: 5 additions & 2 deletions R/get_meter_gsp.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
#'
#' @return a character of the meter-points GSP.
#' @export
get_meter_gsp <- function(mpan = get_meter_details("electricity")[["mpan_mprn"]]) {
get_meter_gsp <- function(
mpan = get_meter_details("electricity")[["mpan_mprn"]]) {
if (is.na(mpan) || mpan == "") {
cli::cli_abort(
"Meter details were missing or incomplete, please supply with {.arg mpan_mprn} and {.arg serial_number} arguments or with {.help [{.fun set_meter_details}](octopusR::set_meter_details)}",
"Meter details were missing or incomplete, please supply with
{.arg mpan_mprn} and {.arg serial_number} arguments or with
{.help [{.fun set_meter_details}](octopusR::set_meter_details)}",
call = rlang::caller_env()
)
}
Expand Down
7 changes: 5 additions & 2 deletions R/meter_details.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ set_meter_details <- function(meter_type = c("electricity", "gas"),
if (missing(mpan_mprn)) {
mpan_mprn <- askpass::askpass(
glue::glue(
"Please enter your {meter_type} meter-point's {ifelse(meter_type == 'electricity', 'MPAN', 'MPRN')}."
"Please enter your {meter_type} meter-point's
{ifelse(meter_type == 'electricity', 'MPAN', 'MPRN')}."
)
)
}
Expand Down Expand Up @@ -80,7 +81,9 @@ get_meter_details <-
}

cli::cli_abort(
"Meter details were missing or incomplete, please supply with {.arg mpan_mprn} and {.arg serial_number} arguments or with {.help [{.fun set_meter_details}](octopusR::set_meter_details)}.",
"Meter details were missing or incomplete, please supply with
{.arg mpan_mprn} and {.arg serial_number} arguments or with
{.help [{.fun set_meter_details}](octopusR::set_meter_details)}.",
call = rlang::caller_env()
)
}
Expand Down
2 changes: 1 addition & 1 deletion inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ Codecov
GSP
MPAN
MPRN
OctopusR
SMETS
datetime
timezone
4 changes: 2 additions & 2 deletions tests/testthat/test-get_consumption.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ test_that("errors properly with incorrect params", {

expect_error(
get_consumption("electricity", period_to = Sys.Date()),
"To use `period_to` you must also provide the `period_from` parameter to create a range"
"To use `period_to` you must also provide the `period_from` parameter .+?$"
)
expect_error(
get_consumption("gas", period_to = Sys.Date()),
"To use `period_to` you must also provide the `period_from` parameter to create a range"
"To use `period_to` you must also provide the `period_from` parameter .+?$"
)
})

Expand Down

0 comments on commit 1c25216

Please sign in to comment.