1% Generated by roxygen2: do not edit by hand 2% Please edit documentation in R/slice.R 3\name{step_slice} 4\alias{step_slice} 5\title{Filter rows by position using dplyr} 6\usage{ 7step_slice( 8 recipe, 9 ..., 10 role = NA, 11 trained = FALSE, 12 inputs = NULL, 13 skip = TRUE, 14 id = rand_id("slice") 15) 16} 17\arguments{ 18\item{recipe}{A recipe object. The step will be added to the 19sequence of operations for this recipe.} 20 21\item{...}{Integer row values. See 22\code{\link[dplyr:slice]{dplyr::slice()}} for more details.} 23 24\item{role}{Not used by this step since no new variables are 25created.} 26 27\item{trained}{A logical to indicate if the quantities for 28preprocessing have been estimated.} 29 30\item{inputs}{Quosure of values given by \code{...}.} 31 32\item{skip}{A logical. Should the step be skipped when the 33recipe is baked by \code{\link[=bake.recipe]{bake.recipe()}}? While all operations are baked 34when \code{\link[=prep.recipe]{prep.recipe()}} is run, some operations may not be able to be 35conducted on new data (e.g. processing the outcome variable(s)). 36Care should be taken when using \code{skip = FALSE}.} 37 38\item{id}{A character string that is unique to this step to identify it.} 39} 40\value{ 41An updated version of \code{recipe} with the new step added to the 42sequence of any existing operations. 43} 44\description{ 45\code{step_slice} creates a \emph{specification} of a recipe step 46that will filter rows using \code{\link[dplyr:slice]{dplyr::slice()}}. 47} 48\details{ 49When an object in the user's global environment is 50referenced in the expression defining the new variable(s), 51it is a good idea to use quasiquotation (e.g. \verb{!!}) 52to embed the value of the object in the expression (to 53be portable between sessions). See the examples. 54 55When you \code{\link[=tidy]{tidy()}} this step, a tibble with column \code{terms} which 56contains the filtering indices is returned. 57} 58\section{Row Filtering}{ 59 60 61This step can entirely remove observations (rows of data), which can have 62unintended and/or problematic consequences when applying the step to new 63data later via \code{\link[=bake.recipe]{bake.recipe()}}. Consider whether \code{skip = TRUE} or 64\code{skip = FALSE} is more appropriate in any given use case. In most instances 65that affect the rows of the data being predicted, this step probably should 66not be applied at all; instead, execute operations like this outside and 67before starting a preprocessing \code{\link[=recipe]{recipe()}}. 68} 69 70\examples{ 71rec <- recipe( ~ ., data = iris) \%>\% 72 step_slice(1:3) 73 74prepped <- prep(rec, training = iris \%>\% slice(1:75)) 75tidy(prepped, number = 1) 76 77library(dplyr) 78 79dplyr_train <- 80 iris \%>\% 81 as_tibble() \%>\% 82 slice(1:75) \%>\% 83 slice(1:3) 84 85rec_train <- bake(prepped, new_data = NULL) 86all.equal(dplyr_train, rec_train) 87 88dplyr_test <- 89 iris \%>\% 90 as_tibble() \%>\% 91 slice(76:150) \%>\% 92 slice(1:3) 93rec_test <- bake(prepped, iris \%>\% slice(76:150)) 94all.equal(dplyr_test, rec_test) 95 96# Embedding the integer expression (or vector) into the 97# recipe: 98 99keep_rows <- 1:6 100 101qq_rec <- 102 recipe( ~ ., data = iris) \%>\% 103 # Embed `keep_rows` in the call using !! 104 step_slice(!!keep_rows) \%>\% 105 prep(training = iris) 106 107tidy(qq_rec, number = 1) 108} 109\seealso{ 110Other row operation steps: 111\code{\link{step_arrange}()}, 112\code{\link{step_filter}()}, 113\code{\link{step_impute_roll}()}, 114\code{\link{step_lag}()}, 115\code{\link{step_naomit}()}, 116\code{\link{step_sample}()}, 117\code{\link{step_shuffle}()} 118 119Other dplyr steps: 120\code{\link{step_arrange}()}, 121\code{\link{step_filter}()}, 122\code{\link{step_mutate_at}()}, 123\code{\link{step_mutate}()}, 124\code{\link{step_rename_at}()}, 125\code{\link{step_rename}()}, 126\code{\link{step_sample}()}, 127\code{\link{step_select}()} 128} 129\concept{dplyr steps} 130\concept{row operation steps} 131