Skip to content

Commit 6e3f0a8

Browse files
authored
migrate probably from Imports to Suggests (#56)
* migrate probably from Imports to Suggests * error in adjustments when probably isn't available * skip tests and examples without probably
1 parent 776c2f4 commit 6e3f0a8

22 files changed

+80
-11
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Imports:
2323
dplyr,
2424
generics,
2525
hardhat,
26-
probably (>= 1.0.3.9000),
2726
purrr,
2827
rlang (>= 1.1.0),
2928
tibble,
@@ -32,6 +31,7 @@ Imports:
3231
Suggests:
3332
dials,
3433
modeldata,
34+
probably (>= 1.0.3.9000),
3535
testthat (>= 3.0.0),
3636
workflows
3737
Remotes:

R/adjust-equivocal-zone.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#' this adjustment just collects metadata on the supplied column names and does
1717
#' not risk data leakage.
1818
#'
19-
#' @examplesIf rlang::is_installed("modeldata")
19+
#' @examplesIf rlang::is_installed(c("probably", "modeldata"))
2020
#' library(dplyr)
2121
#' library(modeldata)
2222
#'
@@ -48,6 +48,8 @@
4848
#' predict(tlr_fit, two_class_example) %>% count(predicted)
4949
#' @export
5050
adjust_equivocal_zone <- function(x, value = 0.1, threshold = 1 / 2) {
51+
validate_probably_available()
52+
5153
check_tailor(x)
5254
if (!is_tune(value)) {
5355
check_number_decimal(value, min = 0, max = 1 / 2)
@@ -94,6 +96,8 @@ print.equivocal_zone <- function(x, ...) {
9496

9597
#' @export
9698
fit.equivocal_zone <- function(object, data, tailor = NULL, ...) {
99+
validate_probably_available()
100+
97101
new_adjustment(
98102
class(object),
99103
inputs = object$inputs,
@@ -107,6 +111,8 @@ fit.equivocal_zone <- function(object, data, tailor = NULL, ...) {
107111

108112
#' @export
109113
predict.equivocal_zone <- function(object, new_data, tailor, ...) {
114+
validate_probably_available()
115+
110116
est_nm <- tailor$columns$estimate
111117
prob_nm <- tailor$columns$probabilities[1]
112118
lvls <- levels(new_data[[est_nm]])

R/adjust-numeric-calibration.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#' situated in a workflow, tailors will automatically be estimated with
2222
#' appropriate subsets of data.
2323
#'
24-
#' @examples
24+
#' @examplesIf rlang::is_installed("probably")
2525
#' library(tibble)
2626
#'
2727
#' # create example data
@@ -46,6 +46,8 @@
4646
#' predict(tlr_fit, d_test)
4747
#' @export
4848
adjust_numeric_calibration <- function(x, method = NULL) {
49+
validate_probably_available()
50+
4951
check_tailor(x, calibration_type = "numeric")
5052
# wait to `check_method()` until `fit()` time
5153
if (!is.null(method)) {
@@ -84,6 +86,8 @@ print.numeric_calibration <- function(x, ...) {
8486

8587
#' @export
8688
fit.numeric_calibration <- function(object, data, tailor = NULL, ...) {
89+
validate_probably_available()
90+
8791
method <- check_method(object$arguments$method, tailor$type)
8892
# todo: adjust_numeric_calibration() should take arguments to pass to
8993
# cal_estimate_* via dots
@@ -111,6 +115,8 @@ fit.numeric_calibration <- function(object, data, tailor = NULL, ...) {
111115

112116
#' @export
113117
predict.numeric_calibration <- function(object, new_data, tailor, ...) {
118+
validate_probably_available()
119+
114120
probably::cal_apply(new_data, object$results$fit)
115121
}
116122

R/adjust-numeric-range.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#' predict(tlr_fit, d)
3434
#' @export
3535
adjust_numeric_range <- function(x, lower_limit = -Inf, upper_limit = Inf) {
36+
validate_probably_available()
37+
3638
# remaining input checks are done via probably::bound_prediction
3739
check_tailor(x)
3840

@@ -87,6 +89,8 @@ print.numeric_range <- function(x, ...) {
8789

8890
#' @export
8991
fit.numeric_range <- function(object, data, tailor = NULL, ...) {
92+
validate_probably_available()
93+
9094
new_adjustment(
9195
class(object),
9296
inputs = object$inputs,
@@ -100,6 +104,8 @@ fit.numeric_range <- function(object, data, tailor = NULL, ...) {
100104

101105
#' @export
102106
predict.numeric_range <- function(object, new_data, tailor, ...) {
107+
validate_probably_available()
108+
103109
est_nm <- tailor$columns$estimate
104110
lo <- object$arguments$lower_limit
105111
hi <- object$arguments$upper_limit

R/adjust-predictions-custom.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#'
1111
#' @inheritSection adjust_equivocal_zone Data Usage
1212
#'
13-
#' @examplesIf rlang::is_installed("modeldata")
13+
#' @examplesIf rlang::is_installed(c("probably", "modeldata"))
1414
#' library(modeldata)
1515
#'
1616
#' head(two_class_example)

R/adjust-probability-calibration.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#' @inheritSection adjust_numeric_calibration Data Usage
1717
#'
1818
#' @examplesIf FALSE
19-
# @examplesIf rlang::is_installed("modeldata")
19+
# @examplesIf rlang::is_installed(c("probably", "modeldata"))
2020
#' library(modeldata)
2121
#'
2222
#' # split example data
@@ -49,6 +49,8 @@
4949
#'
5050
#' @export
5151
adjust_probability_calibration <- function(x, method = NULL) {
52+
validate_probably_available()
53+
5254
check_tailor(x, calibration_type = "probability")
5355
# wait to `check_method()` until `fit()` time
5456
if (!is.null(method)) {
@@ -87,6 +89,8 @@ print.probability_calibration <- function(x, ...) {
8789

8890
#' @export
8991
fit.probability_calibration <- function(object, data, tailor = NULL, ...) {
92+
validate_probably_available()
93+
9094
method <- check_method(object$arguments$method, tailor$type)
9195
# todo: adjust_probability_calibration() should take arguments to pass to
9296
# cal_estimate_* via dots
@@ -115,6 +119,8 @@ fit.probability_calibration <- function(object, data, tailor = NULL, ...) {
115119

116120
#' @export
117121
predict.probability_calibration <- function(object, new_data, tailor, ...) {
122+
validate_probably_available()
123+
118124
probably::cal_apply(
119125
.data = new_data,
120126
object = object$results$fit,

R/adjust-probability-threshold.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#'
1616
#' @inheritSection adjust_equivocal_zone Data Usage
1717
#'
18-
#' @examplesIf rlang::is_installed("modeldata")
18+
#' @examplesIf rlang::is_installed(c("probably", "modeldata"))
1919
#' library(modeldata)
2020
#'
2121
#' # `predicted` gives hard class predictions based on probability threshold .5

R/tailor.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#' `"multiclass"` types, and can also be passed at `fit()` time instead.
3333
#' The column names of class probability estimates. These should be given in
3434
#' the order of the factor levels of the `estimate`.
35-
#' @examplesIf rlang::is_installed("modeldata")
35+
#' @examplesIf rlang::is_installed(c("probably", "modeldata"))
3636
#' library(dplyr)
3737
#' library(modeldata)
3838
#'

R/utils.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,21 @@ is_tailor <- function(x) {
193193
inherits(x, "tailor")
194194
}
195195

196+
validate_probably_available <- function(..., call = caller_env()) {
197+
check_dots_empty()
198+
199+
if (!requireNamespace("probably", quietly = TRUE)) {
200+
cli_abort(
201+
"The {.pkg probably} package must be available to use this adjustment.",
202+
call = call
203+
)
204+
}
205+
206+
invisible()
207+
}
208+
209+
requireNamespace <- NULL
210+
196211
#' @export
197212
#' @keywords internal
198213
#' @rdname tailor-internals

man/adjust_equivocal_zone.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)