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_target_archive()
: tarchives version of targets::tar_target()
function
install.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 = "your-pipeline"
)
#>
#> 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"
)
)