Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
source("renv/activate.R")
source("R/utils.R")
Empty file removed R/.gitkeep
Empty file.
13 changes: 7 additions & 6 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
## Created: 2025-11-05 ##
## Author: Dimitri Baptiste ##
## ----- ##
## Last Modified: 2025-11-05 ##
## Last Modified: 2026-01-20 ##
## Modified By: Dimitri Baptiste ##
## ----- ##
## Copyright (c) 2025 Syndemics Lab at Boston Medical Center ##
## Copyright (c) 2025-2026 Syndemics Lab at Boston Medical Center ##
################################################################################

#' Ensure required packages are installed
Expand All @@ -16,13 +16,14 @@
#' A method that installs packages from CRAN, if they're not yet installed in
#' the current environment, and loads packages.
#'
#' @param packages Character vector of required packages
#' @param ... Package names as strings
#' @return A logical vector giving `TRUE` if the package is installed and
#' available and `FALSE` if there was an issue with installing each of the
#' specified packages
#' @examples
#' ensure_packages(c("dplyr", "here"))
ensure_packages <- function(packages) {
#' ensure_packages("dplyr", "here")
ensure_packages <- function(...) {
packages <- c(...)
return(vapply(
packages,
function(package) {
Expand All @@ -35,6 +36,6 @@ ensure_packages <- function(packages) {
library(package, character.only = TRUE, warn.conflicts = FALSE)
return(require(package, character.only = TRUE))
},
logical(length(packages))
logical(1)
))
}