--- title: "Symlink Tool - Quick Start" # Interactive rendering - uncomment this block and comment out the vignette output below # output: # html_document: # highlight: zenburn # theme: readable # toc: true # toc_float: true # For package builds output: rmarkdown::html_vignette Encoding: UTF-8 vignette: > %\VignetteIndexEntry{Symlink Tool - Quick Start} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r setup, include = FALSE} knitr::opts_chunk$set(collapse = TRUE, comment = "#>") .opt_width <- options(width = 120) hook_output <- knitr::knit_hooks$get("output") flag_eval <- vmTools::dir_supports_links(tempdir()) knitr::knit_hooks$set(output = function(x, options) { if (!is.null(n <- options$out.lines)) { x <- vmTools:::split_line_breaks(x) if (length(x) > n) x <- c(head(x, n %/% 2), "....", tail(x, n %/% 2 + 1)) x <- paste(x, collapse = "\n") } return(hook_output(x, options)) }) ``` ```{r windows_note, echo = FALSE} if (!flag_eval) { knitr::asis_output( "> **Note:** This machine cannot create symlinks (shortcuts) in its temp folder > (on Windows that needs a local disk). Code is shown but not evaluated on this system." ) } ``` ```{r helpers, include = FALSE} library(vmTools) library(data.table) print_tree <- function(x, level = Inf) vmTools:::dir_tree(x, level = level) # Auto-increment YYYY_MM_DD.VV folder names next_version <- function(root, date) { existing <- grep( sprintf("^%s\\.\\d{2}$", date) , list.files(root) , value = TRUE ) idx <- if (length(existing) == 0) 0L else max(as.integer(sub(".*\\.", "", existing))) return(sprintf("%s.%02d", date, idx + 1L)) } show_vars <- c("log_id", "timestamp", "version_name", "action", "comment") ``` # What Is the Symlink Tool? The Symlink Tool (`SLT`) helps you manage a folder of pipeline output runs without a database. Drop it into your pipeline to: - maintain a stable `best/` symlink that always points to your current best run, - keep automatic logs of every status change (created, bested, kept, removed, deleted), and - generate lightweight CSV reports for you and your project officer. > **Windows users:** keep your run folders on a local drive, such as `C:`. > The tool makes links there, and shared network drives will not allow it. > The tool checks every folder when you build it and stops with a plain > message if one will not work. If your folders live on a network drive, run > the tool from Linux instead. This is a fundamental Windows limitation. > See the technical vignette for more details. --- # Walkthrough ## 1 - Setup ```{r setup_root, eval = flag_eval} modeling_root <- file.path(tempdir(), "slt_demo", "modeling_root") dir.create(modeling_root, recursive = TRUE, showWarnings = FALSE) slt <- SLT$new( root_list = list("modeling_root" = modeling_root) , central_log_root = modeling_root ) ``` ```{r reset_cores, include = FALSE} .opt_mc <- options(mc.cores = 1L) ``` The tool is now tied to `modeling_root`. All symlinks, logs, and reports will live there. --- ## 2 - Create Versioned Folders 'Run' your modeling pipeline three times and populate each run with dummy results. Version folder names are yours to choose, with one rule: names the tool uses for its own symlinks (shortcuts) are reserved. That means `best` and `latest`, and anything starting with `keep_` or `remove_`. Any type you add (see `vignette("user_defined_symlink_types", package = "vmTools")`) reserves its name the same way. ```{r make_folders, eval = flag_eval} v1 <- next_version(modeling_root, "2024_02_01") slt$make_new_version_folder(version_name = v1) root_v1 <- slt$return_dynamic_fields()[["VERS_PATHS"]][["modeling_root"]] invisible(file.create(file.path(root_v1, paste0("model_", 1:5, ".csv")))) v2 <- next_version(modeling_root, "2024_02_01") slt$make_new_version_folder(version_name = v2) root_v2 <- slt$return_dynamic_fields()[["VERS_PATHS"]][["modeling_root"]] invisible(file.create(file.path(root_v2, paste0("model_", 1:5, ".csv")))) v3 <- next_version(modeling_root, "2024_02_01") slt$make_new_version_folder(version_name = v3) root_v3 <- slt$return_dynamic_fields()[["VERS_PATHS"]][["modeling_root"]] invisible(file.create(file.path(root_v3, paste0("model_", 1:5, ".csv")))) ``` ```{r tree_after_create, eval = flag_eval} print_tree(modeling_root) ``` --- ## 3 - Mark Latest Tag the most recent run as `latest` - useful when downstream consumers always want the newest output regardless of validation status. ```{r mark_latest_v3, eval = flag_eval} slt$mark_latest(version_name = v3, user_entry = list(comment = "Most recent run")) ``` ```{r tree_latest_v3, eval = flag_eval} print_tree(modeling_root, level = 1) ``` `latest` is a **singleton**: only one folder can hold it at a time, and the tool auto-demotes the previous holder. It is also **mutually exclusive with `best`** - marking a folder `latest` will auto-demote it from `best`, and vice versa. --- ## 4 - Mark Best After reviewing v1 results, promote it to `best`. `best` is also a **singleton** - only one folder holds it at a time. ```{r mark_best_v1, eval = flag_eval} slt$mark_best(version_name = v1, user_entry = list(comment = "First passing run")) ``` ```{r tree_best_v1, eval = flag_eval} print_tree(modeling_root, level = 1) ``` v3 looks even better - promote it. The tool automatically demotes v1. Because v3 currently holds `latest`, promoting it to `best` will also auto-demote it from `latest`. ```{r mark_best_v3, eval = flag_eval} slt$mark_best(version_name = v3, user_entry = list(comment = "Improved priors, 2024 best")) ``` ```{r tree_best_v3, eval = flag_eval} print_tree(modeling_root, level = 1) ``` --- ## 5 - Mark Keep v1 was used in a submitted paper - flag it so it won't be lost or accidentally cleaned up. ```{r mark_keep_v1, eval = flag_eval} slt$mark_keep(version_name = v1, user_entry = list(comment = "Journal submission 2024")) ``` Unlike `best`, many folders can carry a `keep_` symlink simultaneously. ```{r tree_keep, eval = flag_eval} print_tree(modeling_root, level = 1) ``` --- ## 6 - Stage and Delete a Deprecated Run v2 was an experimental dead-end. Stage it for removal, then delete. ```{r mark_remove_v2, eval = flag_eval} slt$mark_remove(version_name = v2, user_entry = list(comment = "Experimental - poor convergence")) ``` ```{r roundup_remove, eval = flag_eval} (to_remove <- slt$roundup_remove()) ``` ```{r delete_v2, eval = flag_eval} for (ver in to_remove$version_name) { slt$delete_version_folders( version_name = ver , user_entry = list(comment = "Cleaning up experimental run") , require_user_input = FALSE ) } ``` --- ## 7 - Reports ### Key-version report Scans every symlink-marked run and shows its current status. v2 is absent - it was deleted. - Reports are built from _versioned folder logs_ for portability, and are the source of truth for all logging and reports. ```{r report_key, eval = flag_eval} data.table::fread(file.path(modeling_root, "report_key_versions.csv"))[, ..show_vars] ``` ### Central log Full audit trail across all runs. - the Central Log is for convenience only - it accumulates appended SLT actions in one place, but is not the source of truth for any logging or reports, since any given modeling folder could be moved/deleted manually by a user. ```{r central_log, eval = flag_eval} path_log <- slt$return_dictionaries()[["LOG_CENTRAL"]][["path"]] data.table::fread(path_log)[, ..show_vars] ``` ```{r final_tree, eval = flag_eval} print_tree(modeling_root, level = 1) ``` --- ## What's Next? This walkthrough covers the core workflow. The technical reference, `vignette("symlink_tool_vignette_technical", package = "vmTools")`, covers: - the Symlink Composer class, which collects `best` symlinks across several projects into a full '`best` set', - several roots per tool instance (e.g., separating model inputs from outputs while keeping them in sync with the same version names) - **_SUNSET NOTICE:_** support for several roots using one tool will likely be sunset in a future version, - a worked example of a user-defined symlink type, - reports and discrepancy detection, and - how links work on Windows. To add your own symlink types, see `vignette("user_defined_symlink_types", package = "vmTools")`. ```{r cleanup, include = FALSE, eval = TRUE} unlink(dirname(modeling_root), recursive = TRUE) options(.opt_width) options(.opt_mc) ```