Skip to contents

Inside params(), arg(type, default) gives a parameter of a generic or trait method its type and, when default is given, its default, an R expression evaluated at each call that omits the argument. Each type constructor has a shorthand, with the constructor's arguments and then a named default: arg_double(min = 0, default = 1) is arg(type_double(min = 0), 1).

Usage

arg(type, default, description = "")

arg_logical(default, description = "")

arg_integer(
  min = NULL,
  max = NULL,
  exclusive_min = NULL,
  exclusive_max = NULL,
  values = NULL,
  default,
  description = ""
)

arg_double(
  min = NULL,
  max = NULL,
  exclusive_min = NULL,
  exclusive_max = NULL,
  infinite = FALSE,
  nan = FALSE,
  values = NULL,
  default,
  description = ""
)

arg_character(pattern = NULL, values = NULL, default, description = "")

arg_raw(default, description = "")

arg_date(default, description = "")

arg_posixct(default, description = "")

arg_factor(levels = NULL, ordered = FALSE, default, description = "")

arg_json(default, description = "")

arg_matrix(
  type = NULL,
  nrow = NULL,
  ncol = NULL,
  of = NULL,
  default,
  description = ""
)

arg_array(type, dim = NULL, default, description = "")

arg_sparse_matrix(
  type = type_double(),
  nrow = NULL,
  ncol = NULL,
  default,
  description = ""
)

arg_table(
  columns = list(),
  open = FALSE,
  rules = list(),
  of = NULL,
  default,
  description = ""
)

arg_vec(
  type,
  min_length = NULL,
  max_length = NULL,
  unique = FALSE,
  default,
  description = ""
)

arg_option(type, default = NULL, description = "")

arg_btree_map(type, keys = NULL, default, description = "")

arg_index_map(type, keys = NULL, default, description = "")

Arguments

type

An r8_field_type or an R8 type: The parameter's type; for arg_vec(), arg_option(), arg_btree_map(), arg_index_map(), arg_matrix(), arg_array(), and arg_sparse_matrix(), the type of the elements or of a present value.

default

Optional expression: The default.

description

Character: What the parameter is, one string, which the declaration keeps: r8schema() writes it, and the roclet r8rd() writes it as the parameter's @param.

min, max, exclusive_min, exclusive_max, values

Optional Numeric: The bounds and admitted values, as type_integer() and type_double() take them; values of arg_character() as type_character() takes it.

infinite, nan

Logical: As type_double() takes them.

pattern

Optional Character: As type_character() takes it.

levels

Optional Character: As type_factor() takes it.

ordered

Logical: As type_factor() takes it.

nrow, ncol

Optional Integer: As type_matrix() takes them.

of

Optional R8 struct type: As type_matrix() and type_table() take it.

dim

Optional Integer: As type_array() takes it.

columns

Named list: As type_table() takes it.

open

Logical: As type_table() takes it.

rules

List: As type_table() takes it.

min_length, max_length

Optional Integer: As vec() takes them.

unique

Logical: As vec() takes it.

keys

Optional r8_field_type: As btree_map() takes it.

Value

In params(), a parameter's declaration. In a function that R calls without a declaration, such as function(x = arg_double()) x, the default, or R's error for a missing argument.

Details

A parameter without a default is required. arg_option(type) has the default NULL: the argument may be omitted and is then absent; arg(option(type)) is required and may be NULL. arg(default = expr) gives a parameter without a type a default that is itself a type, such as arg(default = GBM).

description is named after default: arg_integer(min = 1L, default = 10L, description = "The number of folds."). arg(description = "...") alone describes a parameter without a type or a default.

Each call of the generic checks and converts its typed arguments (generic()).

A type means the same in a parameter as in a field: arg(Range) admits a value of exactly Range, arg(subtype(Range)) also the structs that extend it, arg(dyn(Fit)) any implementor of the trait Fit, and arg(host_class("data.frame")) an object of that class.

See also

Examples

params(x, verbosity = arg_integer(min = 0L, default = 1L))
#> <r8 params>
#>   x
#>   verbosity: integer [0, Inf) = 1L
params(x, n = arg_integer(default = length(x)), weights = arg_option(vec(type_double())))
#> <r8 params>
#>   x
#>   n: integer = length(x)
#>   weights: optional vector of double = NULL