# NOT RUN {
if (identical(Sys.getenv("TAR_LONG_EXAMPLES"), "true")) {
# The tar_group() function simply creates
# a tar_group column to partition the rows
# of a data frame.
data.frame(
x = seq_len(6),
id = rep(letters[seq_len(3)], each = 2)
) %>%
dplyr::group_by(id) %>%
tar_group()
# We use tar_group() below to branch over
# subsets of a data frame defined with dplyr::group_by().
tar_dir({ # tar_dir() runs code from a temporary directory.
tar_script({
library(dplyr)
list(
tar_target(
data,
data.frame(
x = seq_len(6),
id = rep(letters[seq_len(3)], each = 2)
) %>%
group_by(id) %>%
tar_group(),
iteration = "group"
),
tar_target(
sums,
sum(data$x),
pattern = map(data),
iteration = "vector"
)
)
})
tar_make()
tar_read(sums) # Should be c(3, 7, 11).
})
}
# }
Run the code above in your browser using DataLab