Make Your 'targets' Pipelines into a Package

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.


tarchives

R-CMD-check CRANstatus Codecov testcoverage RTargetopia Lifecycle:experimental

Overview

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 version
  • tar_make_archive(): tarchives version of targets::tar_make() function
  • tar_read_archive(): tarchives version of targets::tar_read() function
  • tar_load_archive(): tarchives version of targets::tar_load() function
  • tar_target_archive(): tarchives version of targets::tar_target() function
  • tar_meta_archive(): tarchives version of targets::tar_meta() function
  • tar_manifest_archive(): tarchives version of targets::tar_manifest() function
  • tar_destroy_archive(): tarchives version of targets::tar_destroy() function

Installation

install.packages("tarchives")

Development version

You can install the development version of tarchives from GitHub with:

install.packages("pak")
pak::pak("UchidaMizuki/tarchives")

Usage

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

Declare a target from another pipeline

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"
  )
)

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("tarchives")

0.2.0 by Mizuki Uchida, 3 months ago


https://github.com/UchidaMizuki/tarchives, https://uchidamizuki.github.io/tarchives/


Report a bug at https://github.com/UchidaMizuki/tarchives/issues


Browse source code at https://github.com/cran/tarchives


Authors: Mizuki Uchida [aut, cre, cph] (ORCID:


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports callr, cli, fs, rlang, targets, withr

Suggests testthat


See at CRAN