如何找出R中加载的软件包版本?

本文翻译自:How to find out which package version is loaded in R?

I am in a process of figuring out how to use my university cluster. 我正在弄清楚如何使用我的大学集群。 It has 2 versions of R installed. 它安装了2个版本的R. System wide R 2.11 (Debian 6.0) and R 2.14.2 in non-standard location. 系统范围的R 2.11(Debian 6.0)和R 2.14.2在非标准位置。

I am trying to use MPI together with snow. 我正在尝试将MPI与雪一起使用。 The code I am trying to run is the following 我试图运行的代码如下

library(snow)
library(Rmpi)
cl <- makeMPIcluster(mpi.universe.size()-1)
stopCluster(cl)
mpi.quit()

It works without the problems on R 2.11. 它在R 2.11上没有问题。 (I launch the script with mpirun -H localhost,n1,n2,n3,n4 -n 1 R --slave -f code.R ). (我用mpirun -H localhost,n1,n2,n3,n4 -n 1 R --slave -f code.R )。 Now when I try to do it with R 2.14.2, I get the following message: 现在,当我尝试使用R 2.14.2时,我收到以下消息:

Error: This is R 2.11.1, package 'snow' needs >= 2.12.1
In addition: Warning message:

So it seems that R loads the package snow version compiled for R 2.11. 所以似乎R加载为R 2.11编译的包雪版本。 I've installed snow under R 2.14 into my home folder and I added the following lines to my code: 我已将R 2.14下的雪安装到我的主文件夹中,并在代码中添加了以下行:

.libPaths("/soft/R/lib/R/library")
.libPaths("~/R/x86_64-pc-linux-gnu-library/2.11")
print(.libPaths())
print(sessionInfo())
print(version)

And the output before the error confirms that I am indeed running R 2.14.2 and my R packages folder is first in search path. 并且错误之前的输出确认我确实正在运行R 2.14.2并且我的R packages文件夹首先在搜索路径中。 But I still get the error. 但我仍然得到错误。

So my question is how do I determine which version of package is loaded in R? 所以我的问题是如何确定在R中加载哪个版本的软件包? I can see with installed.packages all the packages which are installed, so maybe there is some function which lists similar information for loaded packages? 我可以在installed.packages中看到所有installed.packages的软件包,所以可能有一些函数列出了加载软件包的类似信息?


#1楼

参考:https://stackoom.com/question/kaRh/如何找出R中加载的软件包版本


#2楼

You can use sessionInfo() to accomplish that. 您可以使用sessionInfo()来完成此任务。

> sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=C                 LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] graphics  grDevices utils     datasets  stats     grid      methods   base     

other attached packages:
[1] ggplot2_0.9.0  reshape2_1.2.1 plyr_1.7.1    

loaded via a namespace (and not attached):
 [1] colorspace_1.1-1   dichromat_1.2-4    digest_0.5.2       MASS_7.3-18        memoise_0.1        munsell_0.3       
 [7] proto_0.3-9.2      RColorBrewer_1.0-5 scales_0.2.0       stringr_0.6       
> 

However, as per comments and the answer below, there are better options 但是,根据评论和下面的答案,有更好的选择

> packageVersion("snow")

[1] '0.3.9' [1]'0.3.9'

Or: 要么:

"Rmpi" %in% loadedNamespaces()

#3楼

To check the version of R execute : R --version 检查R执行的版本: R --version

Or after you are in the R shell print the contents of version$version.string 或者在你进入R shell后打印version$version.string的内容

EDIT 编辑

To check the version of installed packages do the following. 要检查已安装软件包的版本,请执行以下操作。

After loading the library, you can execute sessionInfo () 加载库后,您可以执行sessionInfo ()

But to know the list of all installed packages: 但要知道所有已安装软件包的列表:

packinfo <- installed.packages(fields = c("Package", "Version"))
packinfo[,c("Package", "Version")]

OR to extract a specific library version, once you have extracted the information using the installed.package function as above just use the name of the package in the first dimension of the matrix. 或者要提取特定的库版本,一旦使用上面的installed.package函数提取信息,只需在矩阵的第一维中使用包的名称。

packinfo["RANN",c("Package", "Version")]
packinfo["graphics",c("Package", "Version")]

The above will print the versions of the RANN library and the graphics library. 以上将打印RANN库和图形库的版本。


#4楼

You can use packageVersion to see what version of a package is loaded 您可以使用packageVersion来查看加载了哪个版本的包

> packageVersion("snow")
[1] ‘0.3.9’

Although it sounds like you want to see what version of R you are running, in which case @Justin's sessionInfo suggestion is the way to go 虽然听起来你想看看你正在运行什么版本的R,但在这种情况下@ Justin的sessionInfo建议是要走的路


#5楼

你可以尝试这样的事情:

  1. package_version(R.version)

  2. getRversion()


#6楼

使用以下代码获取系统中安装的R软件包的版本:

installed.packages(fields = c ("Package", "Version"))
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值