我们能够生成R中已加载软件包的列表吗? [英] Are we able to generate a list of loaded packages in R?

查看:92
本文介绍了我们能够生成R中已加载软件包的列表吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个函数可以在R中生成所需软件包的列表?类似于冻结点",因此我们可以快速复制环境吗?

Is there a function where we can generate a list of required packages in R? Something similar to "pip freeze" so we can duplicate environments quickly?

推荐答案

感谢您不要含糊.既然您提到了复制环境,那么这里是有关这些可用软件包的可用性和名称空间的一些信息.

Thanks for not being vague. Since you mentioned duplicating environments, here's some info about availability and namespaces of those available packages.

除了@smci提到的那些功能外,.Packages还将列出库位置路径lib.loc中所有可用的软件包.并且find.package将为您显示软件包的路径.请记住,find.packages可能会在确定程序包的可用性时出现问题.推荐使用require(有关说明,请参见?find.package).

In addition to those functions mentioned by @smci, .Packages will list all packages available in the library location path lib.loc. And find.package will show you the path to the package. Bear in mind that find.packages can present issues when determining availability of a package. require is the recommended method (see ?find.package for explanation).

> x <- .packages(TRUE)
> head(x)
# [1] "assertthat"      "BH"              "car"             "data.table"     
# [5] "digest"          "dplyr"
> f <- find.package(x)
> sample(f, 5)
# [1] "/home/richard/R/x86_64-pc-linux-gnu-library/3.1/latticeExtra"  
# [2] "/home/richard/R/x86_64-pc-linux-gnu-library/3.1/Lahman"        
# [3] "/home/richard/R/x86_64-pc-linux-gnu-library/3.1/microbenchmark"
# [4] "/usr/lib/R/library/tools"                                      
# [5] "/home/richard/R/x86_64-pc-linux-gnu-library/3.1/knitr" 

有关在x中具有这些软件包的名称空间的环境的列表,可以使用getNamespace

For a list of the environments with namespaces for those packages in x, you can use (among others) getNamespace

> sapply(x, getNamespace)[1:3]
# $assertthat
# <environment: namespace:assertthat>

# $BH
# <environment: namespace:BH>

# $car
# <environment: namespace:car>

这篇关于我们能够生成R中已加载软件包的列表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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