Skip to content

Commit da8400f

Browse files
authored
Merge pull request #376 from tidymodels/empty-label
Constructors fill in missing label
2 parents 35c028b + 39446b3 commit da8400f

File tree

3 files changed

+41
-22
lines changed

3 files changed

+41
-22
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
* For space-filling designs for $p$ parameters, there is a higher likelihood of finding a space-filling design for `1 < size <= p`. Also, single-point designs now default to a random grid (#363).
1313

14+
* The constructors, `new_*_parameter()`, now label unlabeled parameter (i.e., constructed with `label = NULL`) as such (#349).
15+
1416
## Breaking changes
1517

1618
* The `grid_*()` functions now error instead of warn when provided with the wrong argument to control the grid size. So `grid_space_filling()`, `grid_random()`, `grid_max_entropy()`, and `grid_latin_hypercube()` now error if used with a `levels` argument and `grid_regular()` now errors if used with a `size` argument (#368).

R/constructors.R

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
#' If set, these will be used by [value_seq()] and [value_sample()].
3333
#'
3434
#' @param label An optional named character string that can be used for
35-
#' printing and plotting. The name should match the object name (e.g.
36-
#' `"mtry"`, `"neighbors"`, etc.)
35+
#' printing and plotting. The name of the label should match the object name
36+
#' (e.g., `"mtry"`, `"neighbors"`, etc.). If `NULL`, the parameter will be
37+
#' labeled with `"Unlabeled parameter"`.
3738
#'
3839
#' @param finalize A function that can be used to set the data-specific
3940
#' values of a parameter (such as the `range`).
@@ -76,16 +77,18 @@ NULL
7677

7778
#' @export
7879
#' @rdname new-param
79-
new_quant_param <- function(type = c("double", "integer"),
80-
range = NULL,
81-
inclusive = NULL,
82-
default = deprecated(),
83-
trans = NULL,
84-
values = NULL,
85-
label = NULL,
86-
finalize = NULL,
87-
...,
88-
call = caller_env()) {
80+
new_quant_param <- function(
81+
type = c("double", "integer"),
82+
range = NULL,
83+
inclusive = NULL,
84+
default = deprecated(),
85+
trans = NULL,
86+
values = NULL,
87+
label = NULL,
88+
finalize = NULL,
89+
...,
90+
call = caller_env()
91+
) {
8992
if (lifecycle::is_present(default)) {
9093
lifecycle::deprecate_stop(
9194
when = "1.1.0",
@@ -156,6 +159,11 @@ new_quant_param <- function(type = c("double", "integer"),
156159
}
157160

158161
check_label(label, call = call)
162+
if (is.null(label)) {
163+
label = "Unlabeled parameter"
164+
names(label) <- "Unlabeled parameter"
165+
}
166+
159167
check_function(finalize, allow_null = TRUE, call = call)
160168

161169
names(range) <- names(inclusive) <- c("lower", "upper")
@@ -189,16 +197,18 @@ new_quant_param <- function(type = c("double", "integer"),
189197

190198
#' @export
191199
#' @rdname new-param
192-
new_qual_param <- function(type = c("character", "logical"),
193-
values,
194-
default = deprecated(),
195-
label = NULL,
196-
finalize = NULL,
197-
...,
198-
call = caller_env()) {
200+
new_qual_param <- function(
201+
type = c("character", "logical"),
202+
values,
203+
default = deprecated(),
204+
label = NULL,
205+
finalize = NULL,
206+
...,
207+
call = caller_env()
208+
) {
199209
if (lifecycle::is_present(default)) {
200210
lifecycle::deprecate_stop(
201-
when = "1.1.0",
211+
when = "1.1.0",
202212
what = "new_qual_param(default)"
203213
)
204214
}
@@ -210,7 +220,13 @@ new_qual_param <- function(type = c("character", "logical"),
210220
"logical" = check_logical(values, call = call),
211221
"character" = check_character(values, call = call)
212222
)
223+
213224
check_label(label, call = call)
225+
if (is.null(label)) {
226+
label = "Unlabeled parameter"
227+
names(label) <- "Unlabeled parameter"
228+
}
229+
214230
check_function(finalize, allow_null = TRUE, call = call)
215231

216232
res <- list(

man/new-param.Rd

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)