Skip to content

Commit e28a935

Browse files
committed
*NEW: libs(takes, naked, pack, names)
1 parent f85c796 commit e28a935

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

R/misc_and_utility.R

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -200,24 +200,27 @@ ggAddR <- function(model, effect = NA, xloc=8, yloc= 10) {
200200
#' @md
201201
#' @examples
202202
#' \dontrun{
203-
#' libs("umx", "OpenMx", "car")
204-
#' libs("umx", c("OpenMx", "car"))
203+
#' libs("car")
204+
#' libs(c("OpenMx", "car"))
205+
#' libs(OpenMx, car)
205206
#' remove.packages()
206207
#' }
207208
libs <- function(... , force.update = FALSE) {
208-
# Capture the unevaluated arguments as a list of symbols
209-
lib_names <- rlang::ensyms(...)
210-
211-
# Convert symbols to character strings
212-
lib_names <- sapply(lib_names, as.character)
213-
214-
# Load the libraries
215-
# lapply(lib_names, library, character.only = TRUE)
216-
217-
# dot.items = list(...) # grab all the dot items
218-
# dot.items = unlist(dot.items) # In case any dot items are lists
219-
220-
for (pack in dot.items) {
209+
# Capture the full call
210+
call <- match.call(expand.dots = TRUE)
211+
212+
# Extract arguments after the function name
213+
args <- as.list(call)[-1]
214+
215+
# If a single character vector was passed
216+
if (length(args) == 1 && is.character(eval(args[[1]], envir = parent.frame()))) {
217+
lib_names <- eval(args[[1]], envir = parent.frame())
218+
} else {
219+
# Convert unevaluated args to strings
220+
lib_names <- sapply(args, deparse)
221+
}
222+
223+
for (pack in lib_names) {
221224
result = tryCatch({
222225
if(force.update){
223226
install.packages(pack)

man/libs.Rd

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)