How to find out which package version is loaded in R?

前端 未结 12 1578
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 14:32

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.

相关标签:
12条回答
  • 2020-11-29 15:10

    You can try something like this:

    1. package_version(R.version)

    2. getRversion()

    0 讨论(0)
  • 2020-11-29 15:11

    GUI solution:

    If you are using RStudio then you can check the package version in the Packages pane.

    0 讨论(0)
  • 2020-11-29 15:12

    Based on the previous answers, here is a simple alternative way of printing the R-version, followed by the name and version of each package loaded in the namespace. It works in the Jupyter notebook, where I had troubles running sessionInfo() and R --version.

    print(paste("R", getRversion()))
    print("-------------")
    for (package_name in sort(loadedNamespaces())) {
        print(paste(package_name, packageVersion(package_name)))
    }
    

    Out:

    [1] "R 3.2.2"
    [1] "-------------"
    [1] "AnnotationDbi 1.32.2"
    [1] "Biobase 2.30.0"
    [1] "BiocGenerics 0.16.1"
    [1] "BiocParallel 1.4.3"
    [1] "DBI 0.3.1"
    [1] "DESeq2 1.10.0"
    [1] "Formula 1.2.1"
    [1] "GenomeInfoDb 1.6.1"
    [1] "GenomicRanges 1.22.3"
    [1] "Hmisc 3.17.0"
    [1] "IRanges 2.4.6"
    [1] "IRdisplay 0.3"
    [1] "IRkernel 0.5"
    
    0 讨论(0)
  • 2020-11-29 15:14

    Old question, but not among the answers is my favorite command to get a quick and short overview of all loaded packages:

    (.packages())
    

    To see which version is installed of all loaded packages, just use the above command to subset installed.packages().

    installed.packages()[(.packages()),3]
    

    By changing the column number (3 for package version) you can get any other information stored in installed.packages() in an easy-to-read matrix. Below is an example for version number and dependency:

    installed.packages()[(.packages()),c(3,5)]
    
    0 讨论(0)
  • Technically speaking, all of the answers at this time are wrong. packageVersion does not return the version of the loaded package. It goes to the disk, and fetches the package version from there.

    This will not make a difference in most cases, but sometimes it does. As far as I can tell, the only way to get the version of a loaded package is the rather hackish:

    asNamespace(pkg)$`.__NAMESPACE__.`$spec[["version"]]
    

    where pkg is the package name.

    EDIT: I am not sure when this function was added, but you can also use getNamespaceVersion, this is cleaner:

    getNamespaceVersion(pkg)
    
    0 讨论(0)
  • 2020-11-29 15:20

    Use the following code to obtain the version of R packages installed in the system:

    installed.packages(fields = c ("Package", "Version"))
    
    0 讨论(0)
提交回复
热议问题