使用单个命令加载多个 R 包 [英] Loading multiple R packages with a single command

查看:69
本文介绍了使用单个命令加载多个 R 包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

多个 R 包可以使用 pacman R 包中的 p_load 函数和以下命令加载:

Multiple R packages may be loaded using the function p_load function from pacman R package with the following command:

pacman::p_load("ggplot2", "lme4")

但是,我想使用这样的命令

However, I want to use the command like this

Packages <- c("ggplot2", "lme4")
pacman::p_load(Packages)

这不起作用.想知道这是如何实现的?

which does not work. Wonder how this can be achieved?

推荐答案

Set character.only on TRUE

Packages <- c("ggplot2", "lme4")
Packages %in% loadedNamespaces() # check if the packages are loaded
# [1] FALSE FALSE

pacman::p_load(Packages, character.only = TRUE)

Packages %in% loadedNamespaces()
# [1] TRUE TRUE

来自?p_load:

"character.only : 逻辑.如果为 TRUE,那么 p_load 将只接受单个输入,它是一个包含要加载的包名称的字符向量."

"character.only : logical. If TRUE then p_load will only accept a single input which is a character vector containing the names of packages to load."

这篇关于使用单个命令加载多个 R 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆