Skip to contents

A wrapper around saveRDS that automatically tracks the output file with DVC and optionally creates a DVC pipeline stage.

Usage

write_rds_dvc(
  object,
  file,
  message = NULL,
  stage_name = NULL,
  deps = NULL,
  metrics = FALSE,
  plots = FALSE,
  params = NULL,
  push = FALSE,
  ...
)

Arguments

object

Object to save

file

Path to write to

message

Optional DVC commit message

stage_name

Optional name for the DVC stage. If provided, creates a pipeline stage.

deps

Character vector of dependency files (optional, for pipeline stages)

metrics

Logical. Whether to mark the output as a DVC metric

plots

Logical. Whether to mark the output as a DVC plot

params

Named list of parameters for the stage (optional)

push

Logical. Whether to push changes to Git remote (default: FALSE)

...

Additional arguments passed to saveRDS

Value

The input object (invisibly) to allow for further piping

Examples

if (FALSE) { # \dontrun{
# Simple tracking
model |> write_rds_dvc(
  "models/model.rds",
  message = "Updated model",
  push = TRUE
)

# As part of a pipeline
model |> write_rds_dvc(
  "models/rf_model.rds",
  message = "Save trained random forest model",
  stage_name = "train_model",
  deps = c("data/processed/training.csv", "R/train_model.R"),
  params = list(ntree = 500),
  push = TRUE
)
} # }