File: tune.R

package info (click to toggle)
r-cran-hardhat 1.2.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,656 kB
  • sloc: sh: 13; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 1,141 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#' Mark arguments for tuning
#'
#' `tune()` is an argument placeholder to be used with the recipes, parsnip, and
#' tune packages. It marks recipes step and parsnip model arguments for tuning.
#'
#' @param id A single character value that can be used to differentiate
#'   parameters that are used in multiple places but have the same name, or if
#'   the user wants to add a note to the specified parameter.
#'
#' @return A call object that echos the user's input.
#'
#' @seealso `tune::tune_grid()`, `tune::tune_bayes()`
#'
#' @export
#'
#' @examples
#' tune()
#' tune("your name here")
#'
#' # In practice, `tune()` is used alongside recipes or parsnip to mark
#' # specific arguments for tuning
#' library(recipes)
#'
#' recipe(mpg ~ ., data = mtcars) %>%
#'   step_normalize(all_numeric_predictors()) %>%
#'   step_pca(all_numeric_predictors, num_comp = tune())
tune <- function(id = "") {
  if (!is.character(id) || length(id) != 1) {
    abort("The `id` should be a single character string.")
  }
  if (is.na(id)) {
    abort("The `id` can't be missing.")
  }

  if (id == "") {
    call("tune")
  } else {
    call("tune", id)
  }
}