View source: R/transform_plan.R
drake_slice | R Documentation |
drake_slice()
is similar to split()
.
Both functions partition data into disjoint subsets,
but whereas split()
returns all the subsets, drake_slice()
returns just one. In other words, drake_slice(..., index = i)
returns split(...)[[i]]
.
Other features:
1. drake_slice()
works on vectors, data frames,
matrices, lists, and arbitrary arrays.
2. Like parallel::splitIndices()
, drake_slice()
tries to
distribute the data uniformly across subsets.
See the examples to learn why splitting is useful in drake
.
drake_slice(data, slices, index, margin = 1L, drop = FALSE)
data |
A list, vector, data frame, matrix, or arbitrary array.
Anything with a |
slices |
Integer of length 1, number of slices (i.e. pieces)
of the whole dataset. Remember, |
index |
Integer of length 1, which piece of the partition to return. |
margin |
Integer of length 1, margin over which to split the data.
For example, for a data frame or matrix,
use |
drop |
Logical, for matrices and arrays.
If |
A subset of data
.
# Simple usage
x <- matrix(seq_len(20), nrow = 5)
x
drake_slice(x, slices = 3, index = 1)
drake_slice(x, slices = 3, index = 2)
drake_slice(x, slices = 3, index = 3)
drake_slice(x, slices = 3, margin = 2, index = 1)
# In drake, you can split a large dataset over multiple targets.
## Not run:
isolate_example("contain side effects", {
plan <- drake_plan(
large_data = mtcars,
data_split = target(
drake_slice(large_data, slices = 32, index = i),
transform = map(i = !!seq_len(32))
)
)
plan
cache <- storr::storr_environment()
make(plan, cache = cache, session_info = FALSE, verbose = FALSE)
readd(data_split_1L, cache = cache)
readd(data_split_2L, cache = cache)
})
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.