Skip to content

Commit ba88b87

Browse files
authored
[Bugfix] ensure_packages (#8)
* [bugfix] address error in `vapply()` in `ensure_packages()` * Include changes from stale branch - Add `.editorconfig`, remove `R/.gitkeep` * Untrack `.editorconfig`
1 parent 2d976bc commit ba88b87

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

.Rprofile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
source("renv/activate.R")
2+
source("R/utils.R")

R/.gitkeep

Whitespace-only changes.

R/utils.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
## Created: 2025-11-05 ##
55
## Author: Dimitri Baptiste ##
66
## ----- ##
7-
## Last Modified: 2025-11-05 ##
7+
## Last Modified: 2026-01-20 ##
88
## Modified By: Dimitri Baptiste ##
99
## ----- ##
10-
## Copyright (c) 2025 Syndemics Lab at Boston Medical Center ##
10+
## Copyright (c) 2025-2026 Syndemics Lab at Boston Medical Center ##
1111
################################################################################
1212

1313
#' Ensure required packages are installed
@@ -16,13 +16,14 @@
1616
#' A method that installs packages from CRAN, if they're not yet installed in
1717
#' the current environment, and loads packages.
1818
#'
19-
#' @param packages Character vector of required packages
19+
#' @param ... Package names as strings
2020
#' @return A logical vector giving `TRUE` if the package is installed and
2121
#' available and `FALSE` if there was an issue with installing each of the
2222
#' specified packages
2323
#' @examples
24-
#' ensure_packages(c("dplyr", "here"))
25-
ensure_packages <- function(packages) {
24+
#' ensure_packages("dplyr", "here")
25+
ensure_packages <- function(...) {
26+
packages <- c(...)
2627
return(vapply(
2728
packages,
2829
function(package) {
@@ -35,6 +36,6 @@ ensure_packages <- function(packages) {
3536
library(package, character.only = TRUE, warn.conflicts = FALSE)
3637
return(require(package, character.only = TRUE))
3738
},
38-
logical(length(packages))
39+
logical(1)
3940
))
4041
}

0 commit comments

Comments
 (0)