Last active
October 8, 2020 14:54
-
-
Save cbrnr/86d70e3d3398f0a9f5a33b1f4ba03a2a to your computer and use it in GitHub Desktop.
Get package versions (by default use all attached packages)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package_versions <- function(packages=NULL, base=FALSE, sort=FALSE) { | |
#' Determine package versions. | |
#' | |
#' @param packages Packages to query; if not specified (or \code{NULL}), | |
#' all currently attached packages are queried. | |
#' @param base If \code{TRUE}, include the base package (R version). | |
#' @param sort If \code{TRUE}, sort package names alphabetically. | |
#' @return Data frame with package names and corresponding versions. | |
if (is.null(packages)) | |
packages <- names(sessionInfo()$otherPkgs) | |
if (base) | |
packages <- c("base", packages) | |
if (sort) | |
packages <- sort(packages) | |
if (!is.null(packages)) { | |
tmp <- data.frame(sapply(sapply(packages, packageVersion, simplify=FALSE), as.character)) | |
colnames(tmp) <- "version" | |
data.frame(package=rownames(tmp), version=tmp[1], row.names=NULL) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment