检查丢失的软件包并安装它们的优雅方法? [英] Elegant way to check for missing packages and install them?

查看:61
本文介绍了检查丢失的软件包并安装它们的优雅方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些天我似乎与合著者分享了很多代码.他们中的许多人是R新手/中级用户,他们没有意识到他们必须安装尚未拥有的软件包.

I seem to be sharing a lot of code with coauthors these days. Many of them are novice/intermediate R users and don't realize that they have to install packages they don't already have.

是否有一种优雅的方式来调用installed.packages(),并将其与我正在加载并安装的安装方式进行比较?

Is there an elegant way to call installed.packages(), compare that to the ones I am loading and install if missing?

推荐答案

是.如果您有软件包列表,请将其与installed.packages()[,"Package"]的输出进行比较,然后安装缺少的软件包.像这样:

Yes. If you have your list of packages, compare it to the output from installed.packages()[,"Package"] and install the missing packages. Something like this:

list.of.packages <- c("ggplot2", "Rcpp")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)

否则:

如果将代码放入软件包中并使其具有依赖性,则在安装软件包时将自动安装它们.

If you put your code in a package and make them dependencies, then they will automatically be installed when you install your package.

这篇关于检查丢失的软件包并安装它们的优雅方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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