简体   繁体   中英

R Packages installed version numbers

I'm trying to sync the packages between Dev and Prod Environment for our client. For that I need to look up for all the packages installed in both the Environments.

To check for all the packages installed I ran the following command :

installed.packages(fields=c("Package","Version"))

However, when I run this command I don't get the version of the packages. I just get the version of R Installed.

See Screenhshot : 在此处输入图片说明

Also if I try to run the below command then it will give me the version for individual package:

packageDescription("packageName")$Version

Can someone help me here with the command so that I can get all the packages installed in R (through Putty command line) with their respective versions so that I can copy those values in excel and compare them?

installed.packages will always return the package version, in the Version column.

pkgs <- installed.packages()
vers <- pkgs[, "Version"]

This will be a character vector, which is a tad inconvenient if you want to compare versions. The package_version function will turn a character string like "3.3.2" into an object that is more suitable for the task.

package_version(vers["stats"])
# '3.3.2'

package_version(vers["stats"]) > package_version("3.1")
# TRUE

package_version(vers["stats"]) == packageVersion("stats")  # note function names
# TRUE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM