https://wlandau.github.io/targets-intro/#/section
https://rstudio.cloud/project/1430691
Let's explore the repository and identify the key files:
- _targets.R
- R/functions.R
Let's install packages:
install.packages(c("targets","tarchetypes","rmarkdown","biglm", "dplyr","ggplot2","readr","tidyr","visNetwork"))
Now we can make sure everything is working by running targets
: tar_make()
.
Let's delete index.html
and run tar_outdated()
and tar_visnetwork()
.
Creating functions for targets raw_data
and data
# _targets.R file:
library(targets)
list(
tar_target(name = index, command = c(1, 2)),
tar_target(
name = result,
command = index + 7,
pattern = map(index)
)
)
There is also a way to easily branch over
- all rows of a table
- all groups of a
tibble
likedplyr::group_by()
does (see here) - iterations (see here)
- all combinations of a group of parameters (see here)
Creating a function that could run on one CPU or several ones.
Install the clustermq
package and modify _targets.R
.
# _targets.R file:
library(targets)
source('R/functions.R')
options(clustermq.scheduler = "multiprocess")
count_until <- function(x) {
count = 0L
while (count != x) {
count = count + 1L
}
}
list(
tar_target(name = x, command = rep(100000006,10)),
tar_target(
name = result,
command = count_until(x),
pattern = map(x)
)
)
renv::restore() # Yes you want to initiate first
If it does not work, let's focus on just some packages:
renv::install(c("targets","tarchetypes","biglm", "dplyr","ggplot2","readr","tidyr"))
If you don't have renv
installed:
install.packages(c("targets","tarchetypes","biglm", "dplyr","ggplot2","readr","tidyr"))
Or try pak
, it's very fast and friendly
install.packages("pak")
pak::pkg_install(c("targets","tarchetypes","biglm", “dplyr","ggplot2","readr","tidyr"))
https://wlandau.github.io/targets-intro/#/section
The presentation: https://wlandau.github.io/targets-tutorial/#1
The code: https://github.com/wlandau/stantargets-example-validation
https://books.ropensci.org/targets/