File: has_role.Rd

package info (click to toggle)
r-cran-recipes 1.0.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,636 kB
  • sloc: sh: 37; makefile: 2
file content (150 lines) | stat: -rw-r--r-- 3,826 bytes parent folder | download | duplicates (2)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/selections.R
\name{has_role}
\alias{has_role}
\alias{has_type}
\alias{all_outcomes}
\alias{all_predictors}
\alias{all_date}
\alias{all_date_predictors}
\alias{all_datetime}
\alias{all_datetime_predictors}
\alias{all_double}
\alias{all_double_predictors}
\alias{all_factor}
\alias{all_factor_predictors}
\alias{all_integer}
\alias{all_integer_predictors}
\alias{all_logical}
\alias{all_logical_predictors}
\alias{all_nominal}
\alias{all_nominal_predictors}
\alias{all_numeric}
\alias{all_numeric_predictors}
\alias{all_ordered}
\alias{all_ordered_predictors}
\alias{all_string}
\alias{all_string_predictors}
\alias{all_unordered}
\alias{all_unordered_predictors}
\alias{current_info}
\title{Role Selection}
\usage{
has_role(match = "predictor")

has_type(match = "numeric")

all_outcomes()

all_predictors()

all_date()

all_date_predictors()

all_datetime()

all_datetime_predictors()

all_double()

all_double_predictors()

all_factor()

all_factor_predictors()

all_integer()

all_integer_predictors()

all_logical()

all_logical_predictors()

all_nominal()

all_nominal_predictors()

all_numeric()

all_numeric_predictors()

all_ordered()

all_ordered_predictors()

all_string()

all_string_predictors()

all_unordered()

all_unordered_predictors()

current_info()
}
\arguments{
\item{match}{A single character string for the query. Exact
matching is used (i.e. regular expressions won't work).}
}
\value{
Selector functions return an integer vector.

\code{current_info()} returns an environment with objects \code{vars} and \code{data}.
}
\description{
\code{has_role()}, \code{all_predictors()}, and \code{all_outcomes()} can be used to
select variables in a formula that have certain roles.

\strong{In most cases}, the right approach for users will be use to use the
predictor-specific selectors such as \code{all_numeric_predictors()} and
\code{all_nominal_predictors()}. In general you should be careful about using
\code{-all_outcomes()} if a \verb{*_predictors()} selector would do what you want.

Similarly, \code{has_type()}, \code{all_numeric()}, \code{all_integer()}, \code{all_double()},
\code{all_nominal()}, \code{all_ordered()}, \code{all_unordered()}, \code{all_factor()},
\code{all_string()}, \code{all_date()} and \code{all_datetime()} are used to select columns
based on their data type.

\code{all_factor()} captures ordered and unordered factors, \code{all_string()}
captures characters, \code{all_unordered()} captures unordered factors and
characters, \code{all_ordered()} captures ordered factors, \code{all_nominal()}
captures characters, unordered and ordered factors.

\code{all_integer()} captures integers, \code{all_double()} captures doubles,
\code{all_numeric()} captures all kinds of numeric.

\code{all_date()} captures \code{\link[=Date]{Date()}} variables, \code{all_datetime()} captures
\code{\link[=POSIXct]{POSIXct()}} variables.

See \link{selections} for more details.

\code{current_info()} is an internal function.

All of these functions have have limited utility outside of column selection
in step functions.
}
\examples{
\dontshow{if (rlang::is_installed("modeldata")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
data(biomass, package = "modeldata")

rec <- recipe(biomass) \%>\%
  update_role(
    carbon, hydrogen, oxygen, nitrogen, sulfur,
    new_role = "predictor"
  ) \%>\%
  update_role(HHV, new_role = "outcome") \%>\%
  update_role(sample, new_role = "id variable") \%>\%
  update_role(dataset, new_role = "splitting indicator")

recipe_info <- summary(rec)
recipe_info

# Centering on all predictors except carbon
rec \%>\%
  step_center(all_predictors(), -carbon) \%>\%
  prep(training = biomass) \%>\%
  bake(new_data = NULL)
\dontshow{\}) # examplesIf}
}