DOI-USGS / DOI-USGS/scipiper

Helper function to identify pipeline packages

Open
#152 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
R
Stars
10
Forks
12
PR merge metrics
No merged PRs in 30d

Description

Don't think there is any active development, but I have always wanted an easy way to see what packages are used by a pipeline. Re-installing R and having to install packages from the start inspired me to write this teeny function. Let me know if it could be useful and I can make a PR to `scipiper`.

```r
#' @description skim yml files and return all the packages used by a scipiper pipeline
#'
#' @param yml_files a vector of yml files to search; default is NULL which will look at any
#' the contents of any yml file in the top level director
#' @param only_missing logical to say whether the returned vector of packages should show
#' all needed by the ymls or just those that are not currently installed
#'
#' @value character vector of package names
#'
find_required_packages <- function(yml_files = NULL, only_missing = FALSE) {
if(is.null(yml_files)) {
yml_files <- list.files(pattern = "*.yml")
}

yml_pkg_list <- lapply(yml_files, function(fn) yaml::yaml.load_file(fn)$packages)
uniq_pkgs <- unique(unlist(yml_pkg_list))

if(only_missing) {
existing_pkgs <- installed.packages()
missing_pkgs <- uniq_pkgs[!uniq_pkgs %in% existing_pkgs]
return(missing_pkgs)
} else {
return(uniq_pkgs)
}
}
```

Used it like this:
```r
> find_required_packages()
[1] "dplyr" "scipiper" "dataRetrieval" "sf" "httr" "sbtools"
[7] "smoothr" "lwgeom" "readxl" "feather" "readr" "rlang"
[13] "raster" "purrr" "maps" "sp" "ncdf4" "stringr"
[19] "yaml" "progress" "googledrive" "MESS" "tidyr" "tools"
[25] "testit" "odbc" "assertthat" "tidyselect" "ggplot2" "lakeattributes"
[31] "leaflet"

> find_required_packages(only_missing = TRUE)
[1] "dataRetrieval" "sf" "sbtools" "smoothr" "lwgeom" "feather"
[7] "raster" "maps" "ncdf4" "MESS" "testit" "odbc"
[13] "lakeattributes" "leaflet"
```

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the scipiper package structure and how pipeline YAML files expose their `packages` entries. Compare the proposed `find_required_packages` behavior for default YAML discovery and `only_missing`; done means returning the expected unique package names and missing-package subset in the project’s established style.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.