如何找出 R 中加载了哪个包版本? [英] How to find out which package version is loaded in R?

查看:38
本文介绍了如何找出 R 中加载了哪个包版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究如何使用我的大学集群.它安装了 2 个版本的 R.系统范围的 R 2.11 (Debian 6.0) 和 R 2.14.2 在非标准位置.

I am in a process of figuring out how to use my university cluster. It has 2 versions of R installed. System wide R 2.11 (Debian 6.0) and R 2.14.2 in non-standard location.

我正在尝试将 MPI 与雪一起使用.我尝试运行的代码如下

I am trying to use MPI together with snow. The code I am trying to run is the following

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

它在 R 2.11 上没有问题.(我使用 mpirun -H localhost,n1,n2,n3,n4 -n 1 R --slave -f code.R 启动脚本).现在,当我尝试使用 R 2.14.2 执行此操作时,我收到以下消息:

It works without the problems on R 2.11. (I launch the script with 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:

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

所以看起来 R 加载了为 R 2.11 编译的包雪版本.我已将 R 2.14 下的 snow 安装到我的主文件夹中,并将以下几行添加到我的代码中:

So it seems that R loads the package snow version compiled for R 2.11. I've installed snow under R 2.14 into my home folder and I added the following lines to my code:

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

错误前的输出确认我确实在运行 R 2.14.2,并且我的 R 包文件夹位于搜索路径的首位.但我仍然得到错误.

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. But I still get the error.

所以我的问题是如何确定 R 中加载了哪个版本的包?我可以通过 installed.packages 查看所有已安装的包,所以也许有一些函数列出了已加载包的类似信息?

So my question is how do I determine which version of package is loaded in 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?

推荐答案

你可以使用 sessionInfo() 来完成.

You can use sessionInfo() to accomplish that.

> 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’

或者:

"Rmpi" %in% loadedNamespaces()

这篇关于如何找出 R 中加载了哪个包版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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