### Complete gittargets Workflow Example Source: https://context7.com/ropensci/gittargets/llms.txt A comprehensive example showing the initialization of a pipeline, creating snapshots, branching, and restoring data states using gittargets and gert. ```R library(targets) library(gittargets) library(gert) tar_script({ list( tar_target(data, datasets::airquality), tar_target(clean_data, na.omit(data)), tar_target(model, lm(Ozone ~ Wind + Temp, data = clean_data)), tar_target(summary_stats, summary(model)) ) }) tar_make() git_init() git_add("_targets.R") git_commit("Initial airquality analysis pipeline") git_branch_create("main") tar_git_init() tar_git_snapshot(status = FALSE) git_branch_create("feature-solar-model") tar_script({ list( tar_target(data, datasets::airquality), tar_target(clean_data, na.omit(data)), tar_target(model, lm(Ozone ~ Solar.R + Wind + Temp, data = clean_data)), tar_target(summary_stats, summary(model)) ) }) tar_make() git_add("_targets.R") git_commit("Add Solar.R predictor to model") tar_git_snapshot(status = FALSE) git_branch_checkout("main") tar_git_checkout() tar_read(summary_stats) ``` -------------------------------- ### Install gittargets R Package Source: https://github.com/ropensci/gittargets/blob/main/README.md Provides commands to install the gittargets R package from CRAN, GitHub (development), or rOpenSci's universe. It also outlines prerequisites for Git command-line tools and configuration. ```R install.packages("gittargets") remotes::install_github("ropensci/gittargets") install.packages("gittargets", repos = "https://ropensci.r-universe.dev") ``` -------------------------------- ### tar_git_ok Source: https://context7.com/ropensci/gittargets/llms.txt Verifies that Git is installed and configured with the required user name and email settings. ```APIDOC ## tar_git_ok ### Description Checks if Git is properly installed and configured on your system. Verifies that the Git binary is accessible and that the global user.name and user.email are configured. ### Method Function Call ### Parameters #### Query Parameters - **verbose** (logical) - Optional - Whether to print configuration details to the console. Defaults to TRUE. ### Response - **result** (logical) - Returns TRUE if Git is correctly configured, FALSE otherwise. ``` -------------------------------- ### Check gittargets Installation and Git Configuration Source: https://github.com/ropensci/gittargets/blob/main/README.md Verifies the installation of the gittargets package and checks if the necessary Git executable is reachable and if global Git user name and email are configured. Returns TRUE if all checks pass. ```R tar_git_ok() #> ✓ Git binary: /path/to/git #> ✓ Git config global user name: your_user_name #> ✓ Git config global user email: your_email@example.com #> [1] TRUE ``` -------------------------------- ### Define a Simple targets Pipeline Source: https://github.com/ropensci/gittargets/blob/main/README.md An example of defining a basic data analysis pipeline using the targets R package. It includes targets for loading data and building a linear model. ```R # _targets.R library(targets) list( tar_target(data, airquality), tar_target(model, lm(Ozone ~ Wind, data = data)) # Regress on wind speed. ) ``` -------------------------------- ### Get gittargets Citation (R) Source: https://github.com/ropensci/gittargets/blob/main/README.md Retrieves the citation information for the gittargets package. This is standard practice for acknowledging the use of a package in academic or published work. ```r citation("gittargets") #> #> To cite gittargets in publications use: #> #> William Michael Landau (2021). gittargets: Version Control for the #> targets Package. https://docs.ropensci.org/gittargets/, #> https://github.com/ropensci/gittargets. #> #> A BibTeX entry for LaTeX users is #> #> @Manual{, #> title = {gittargets: Version Control for the Targets Package}, #> author = {William Michael Landau}, #> note = {https://docs.ropensci.org/gittargets/, https://github.com/ropensci/gittargets}, #> year = {2021}, #> } ``` -------------------------------- ### GET tar_git_status_targets Source: https://context7.com/ropensci/gittargets/llms.txt Checks which targets are outdated relative to the current Git snapshot. ```APIDOC ## GET tar_git_status_targets ### Description Identifies which targets in the pipeline are currently outdated compared to the data stored in the Git snapshot. ### Method GET ### Endpoint tar_git_status_targets() ### Parameters #### Query Parameters - **script** (string) - Optional - Path to the targets script file. - **store** (string) - Optional - Path to the targets data store. ### Request Example tar_git_status_targets(script = "_targets.R", store = "_targets") ### Response #### Success Response (200) - **outdated** (vector) - A character vector of target names that are out of sync. #### Response Example [1] "model" "summary_stats" ``` -------------------------------- ### Get Code Repository Status with tar_git_status_code Source: https://context7.com/ropensci/gittargets/llms.txt Returns the Git status specifically for the code repository as a data frame. It can also check the status of a different code directory and returns NULL if no Git repository is found. ```r library(gittargets) status <- tar_git_status_code() print(status) status <- tar_git_status_code() if (is.null(status)) { message("No code repository found. Run gert::git_init()") } status <- tar_git_status_code(code = "/path/to/project") ``` -------------------------------- ### Get Data Repository Status with tar_git_status_data Source: https://context7.com/ropensci/gittargets/llms.txt Returns the Git status of the data repository as a data frame, indicating modified or new data files. It can also use a custom store location and returns NULL if no data repository is found. ```r library(gittargets) status <- tar_git_status_data() print(status) status <- tar_git_status_data() if (is.null(status)) { message("No data repository found. Run tar_git_init()") } status <- tar_git_status_data(store = "custom_targets") ``` -------------------------------- ### Initialize Git Repository for Data Store Source: https://context7.com/ropensci/gittargets/llms.txt Sets up a Git repository inside the _targets directory. It supports Git LFS for large files and allows specifying custom store locations. ```r library(targets) library(gittargets) # First, create and run a targets pipeline tar_script({ list( tar_target(data, datasets::airquality), tar_target(model, lm(Ozone ~ Wind, data = data)) ) }) tar_make() # Initialize the data repository with Git LFS support tar_git_init() # Initialize without Git LFS tar_git_init(git_lfs = FALSE) # Use a custom data store location tar_git_init(store = "custom_targets_store") ``` -------------------------------- ### tar_git_init Source: https://context7.com/ropensci/gittargets/llms.txt Initializes a Git repository within the _targets data store to track data snapshots. ```APIDOC ## tar_git_init ### Description Initializes a Git repository inside the _targets directory to track data snapshots independently from the code repository. Configures Git LFS for large file handling by default. ### Method Function Call ### Parameters #### Query Parameters - **git_lfs** (logical) - Optional - Whether to enable Git LFS. Defaults to TRUE. - **store** (character) - Optional - Path to the targets data store. Defaults to '_targets'. ``` -------------------------------- ### Initialize Git LFS for Data Store (gittargets) Source: https://github.com/ropensci/gittargets/blob/main/README.md Initializes a Git LFS repository for the targets data store. This command is crucial for enabling version control of pipeline outputs using Git Large File Storage. ```r tar_git_init() ``` -------------------------------- ### POST tar_git_snapshot Source: https://context7.com/ropensci/gittargets/llms.txt Creates a new snapshot of the current targets pipeline data. ```APIDOC ## POST tar_git_snapshot ### Description Commits the current state of the targets data store to the Git repository as a snapshot. ### Method POST ### Endpoint tar_git_snapshot() ### Parameters #### Request Body - **status** (boolean) - Optional - Whether to check status before snapshotting. - **message** (string) - Optional - Commit message for the snapshot. ### Request Example tar_git_snapshot(status = FALSE) ### Response #### Success Response (200) - **result** (string) - Confirmation of the snapshot creation. ``` -------------------------------- ### Create Data Snapshots Source: https://context7.com/ropensci/gittargets/llms.txt Creates a Git commit in the data repository that maps to the current code commit. This allows maintaining multiple data states linked to specific points in code history. ```r library(targets) library(gittargets) library(gert) # Initialize code and data repositories git_init() git_add("_targets.R") git_commit("Initial pipeline with airquality data") tar_git_init() # Create a data snapshot tar_git_snapshot() # Create snapshot without interactive confirmation tar_git_snapshot(status = FALSE) # Snapshot with a custom message tar_git_snapshot( message = "Snapshot after feature engineering complete", status = FALSE, verbose = TRUE ) # Snapshot for a specific code commit reference tar_git_snapshot(ref = "feature-branch", status = FALSE) ``` -------------------------------- ### Checkout Git Branch Source: https://github.com/ropensci/gittargets/blob/main/README.md Illustrates how to switch to a different branch in a Git repository using the gert package. This action is relevant in the context of gittargets for managing code versions and their associated data. ```R gert::git_branch_checkout(branch = "other-model") ``` -------------------------------- ### Run and Check targets Pipeline Status Source: https://github.com/ropensci/gittargets/blob/main/README.md Demonstrates how to run a targets pipeline using tar_make() and check for outdated targets using tar_outdated(). An empty output from tar_outdated() indicates all targets are up to date. ```R tar_make() #> • start target data #> • built target data #> • start target model #> • built target model #> • end pipeline tar_outdated() #> character(0) ``` -------------------------------- ### Verify Git Configuration for gittargets Source: https://context7.com/ropensci/gittargets/llms.txt Checks if the Git binary is accessible and if global user name and email are configured. This is a prerequisite for creating commits within the data store. ```r library(gittargets) # Check Git installation and configuration tar_git_ok() # Suppress console output and just get the logical result is_configured <- tar_git_ok(verbose = FALSE) if (!is_configured) { stop("Please configure Git before using gittargets") } ``` -------------------------------- ### Create Data Snapshot (gittargets) Source: https://github.com/ropensci/gittargets/blob/main/README.md Creates a data snapshot for the current code commit. This function records the state of the pipeline's data outputs at a specific point in time, allowing for later retrieval. ```r tar_git_snapshot() ``` -------------------------------- ### Define Targets Pipeline (_targets.R) Source: https://github.com/ropensci/gittargets/blob/main/README.md Defines a simple targets pipeline with two targets: 'data' which loads the airquality dataset, and 'model' which fits a linear model. This is the basic structure for a targets pipeline. ```r library(targets) list( tar_target(data, airquality), tar_target(model, lm(Ozone ~ Temp, data = data)) # Regress on temperature. ) ``` -------------------------------- ### POST tar_git_checkout Source: https://context7.com/ropensci/gittargets/llms.txt Restores the data store to match the current Git branch state. ```APIDOC ## POST tar_git_checkout ### Description Updates the targets data store to match the data snapshot associated with the current Git branch. ### Method POST ### Endpoint tar_git_checkout() ### Parameters #### Request Body - **branch** (string) - Optional - The branch to checkout. ### Request Example tar_git_checkout() ### Response #### Success Response (200) - **status** (string) - Confirmation that the data store has been restored. ``` -------------------------------- ### Revert Data to Snapshot (gittargets) Source: https://github.com/ropensci/gittargets/blob/main/README.md Reverts the pipeline's data to a previously created snapshot. This is useful for returning to a known working state or for analyzing data from a specific past commit. ```r tar_git_checkout() ``` -------------------------------- ### Checkout Data Snapshot with gittargets Source: https://context7.com/ropensci/gittargets/llms.txt Restores a previous data snapshot for the current code commit. It can also checkout data for a specific Git reference or force overwrite uncommitted changes. ```r tar_read(result) tar_git_checkout() tar_read(result) tar_outdated() tar_git_checkout(ref = "v1.0.0") tar_git_checkout(force = TRUE) ``` -------------------------------- ### Check Pipeline Status with gittargets Source: https://context7.com/ropensci/gittargets/llms.txt Demonstrates how to check if targets are outdated relative to the current Git state. This is essential for ensuring data and code synchronization before running pipelines. ```R outdated <- tar_git_status_targets() print(outdated) if (nrow(tar_git_status_targets()) > 0) { message("Run tar_make() before creating a snapshot") } outdated <- tar_git_status_targets( script = "analysis/_targets.R", store = "analysis/_targets" ) ``` -------------------------------- ### tar_git_snapshot Source: https://context7.com/ropensci/gittargets/llms.txt Creates a data snapshot (Git commit) in the data repository corresponding to the current code commit. ```APIDOC ## tar_git_snapshot ### Description Creates a data snapshot that maps to the current code commit. Each snapshot is stored on a branch specific to the code commit. ### Method Function Call ### Parameters #### Query Parameters - **message** (character) - Optional - Commit message for the snapshot. - **status** (logical) - Optional - Whether to show status before snapshotting. Defaults to TRUE. - **ref** (character) - Optional - Specific code commit reference to map the snapshot to. ``` -------------------------------- ### Check Project Status with tar_git_status Source: https://context7.com/ropensci/gittargets/llms.txt Provides a comprehensive status report of the project, including Git status for both data and code repositories, and identifies any outdated targets. This is crucial before creating new snapshots. ```r library(gittargets) tar_git_status() ``` -------------------------------- ### tar_git_checkout Source: https://context7.com/ropensci/gittargets/llms.txt Restores the data store to match the state of a specific code commit. ```APIDOC ## tar_git_checkout ### Description Checks out a data snapshot corresponding to a specific code commit, restoring the data store to that historical state. ### Method Function Call ### Parameters #### Query Parameters - **ref** (character) - Required - The Git commit hash or branch name to restore the data store to. ``` -------------------------------- ### Identify Outdated Targets with tar_git_status_targets Source: https://context7.com/ropensci/gittargets/llms.txt Returns a tibble listing all targets that are currently outdated, meaning their dependencies have changed since the last snapshot. This helps ensure the pipeline is up-to-date before creating new snapshots. ```r library(gittargets) outdated <- tar_git_status_targets() print(outdated) ``` -------------------------------- ### View Data Snapshots with tar_git_log Source: https://context7.com/ropensci/gittargets/llms.txt Retrieves a data frame of all available data snapshots for the current code branch, including commit messages and timestamps. It supports querying specific branches, limiting results, and accessing specific columns. ```r library(gittargets) log <- tar_git_log() print(log) log <- tar_git_log(branch = "feature-branch") log <- tar_git_log(max = 50) available_commits <- log$commit_code latest_snapshot_time <- max(log$time_data) ``` -------------------------------- ### Check Outdated Targets (R) Source: https://github.com/ropensci/gittargets/blob/main/README.md Checks which targets in the pipeline are outdated. This function is part of the targets package and helps identify which parts of the pipeline need to be re-run. ```r tar_outdated() #> [1] "model" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.