Precursor utilities for the `flo` R package for loading packages/R scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load_my_pkgs <- function(pkgs) { | |
for (i in seq_along(pkgs)) { | |
library( | |
pkgs[i], character.only = TRUE, | |
warn.conflicts = FALSE, | |
quietly = TRUE | |
) | |
} | |
} | |
load_my_r <- function(files) { | |
for (i in seq_along(files)) { | |
source(files[i], echo = FALSE) | |
} | |
} | |
my_r <- function() { | |
if (!fs::dir_exists("R")) { | |
cli::cli_abort( | |
"Cannot find {.path R/} directory" | |
) | |
} | |
files <- fs::dir_ls("R", glob = "*.R|*.r") | |
load_my_r( | |
files = files[files != "R/packages.R"] | |
) | |
} | |
my_pkgs <- function() { | |
if (fs::file_exists("DESCRIPTION")) { | |
pkgs <- desc::desc_get_deps(file = "DESCRIPTION")$package | |
} | |
if (fs::file_exists("R/packages.R")) { | |
pkgs <- readLines("R/packages.R") | |
} | |
if (!exists("pkgs")) { | |
cli::cli_abort( | |
"Cannot find {.path DESCRIPTION} or {.path R/packages.R} file" | |
) | |
} else { | |
load_my_pkgs(pkgs = pkgs) | |
} | |
} | |
my <- function(pkgs = TRUE, r = TRUE) { | |
if (pkgs) { | |
my_pkgs() | |
} | |
if (r) { | |
my_r() | |
} | |
} | |
my() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment