Runs 'targets' pipelines bundled inside a package and caches the results in the R user cache directory, so that users of the package do not need to rerun the pipeline themselves. Package authors can update the cached results at any time by releasing a new package version.
The goal of tarchives is to make targets pipelines into a package. It runs targets pipeline in /inst/tarchives and stores the results in the R user directory. This means that the user does not have to run the process repeatedly, and the developer has the flexibility to update the data as versions are updated.
This package is a wrapper for the targets package and contains the following functions:
tar_archive(): Convert the targets function to tarchives versiontar_make_archive(): tarchives version of targets::tar_make()
functiontar_read_archive(): tarchives version of targets::tar_read()
functiontar_get_archive(): Build an archived pipeline if needed and read a
target in one calltar_load_archive(): tarchives version of targets::tar_load()
functiontar_target_archive(): tarchives version of targets::tar_target()
functiontar_meta_archive(): tarchives version of targets::tar_meta()
functiontar_manifest_archive(): tarchives version of
targets::tar_manifest() functiontar_destroy_archive(): tarchives version of targets::tar_destroy()
functiontar_download_file(): Download source files into the store of the
running pipelineinstall.packages("tarchives")
You can install the development version of tarchives from GitHub with:
install.packages("pak")
pak::pak("UchidaMizuki/tarchives")
To use tarchives, run the following code under the package you are developing:
library(tarchives)
use_tarchives()
This will create an inst/tarchives directory in your package, where
your target pipelines will be stored. You can define your target
pipeline in the _targets.R file in the inst/tarchives/example-model
directory as follows:
# inst/tarchives/example-model/_targets.R
library(targets)
list(
tar_target(
data,
iris[iris$Species != "setosa", ]
),
tar_target(
model,
lm(Sepal.Width ~ Sepal.Length, data)
)
)
If you have created a package called your-package and saved the
pipeline to a directory called example-model in the inst/tarchives
directory, you can run it using the following command:
tar_make_archive(
package = "your-package",
pipeline = "example-model"
)
Then you can read the results using the tar_read_archive() function:
tar_read_archive(
model,
package = "your-package",
pipeline = "example-model"
)
#>
#> Call:
#> lm(formula = Sepal.Width ~ Sepal.Length, data = data)
#>
#> Coefficients:
#> (Intercept) Sepal.Length
#> 1.131 0.278
You can also declare a target from another pipeline using the
tar_target_archive() function. For example, if you want to declare the
data and model targets from the example-model pipeline in your
_targets.R file, you can do it as follows:
library(targets)
tar_source()
list(
tarchives::tar_target_archive(
data,
package = "tarchives",
pipeline = "example-model"
),
tarchives::tar_target_archive(
model,
package = "tarchives",
pipeline = "example-model"
)
)
Pipelines often start by downloading their source files. Because
tar_make_archive() runs a pipeline from its directory inside the
installed package, a relative path such as "_targets/user/table.xlsx"
would write into the package library. Use tar_download_file() in the
command of a file target instead, which downloads into the store of the
running pipeline:
library(targets)
list(
tar_target(
file_table,
tarchives::tar_download_file(
url = "https://example.org/table.xlsx",
file = "table.xlsx"
),
format = "file"
),
tar_target(
table,
readxl::read_excel(file_table)
)
)