From 141ca866ca686b1570822beae859f14b3c8d9515 Mon Sep 17 00:00:00 2001 From: Craig Williams Date: Thu, 16 Jun 2022 13:09:14 +0100 Subject: [PATCH] Function to list all imported packages in a project --- NAMESPACE | 1 + R/list_imports.R | 17 +++++++++++++++++ man/list_imports.Rd | 16 ++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 R/list_imports.R create mode 100644 man/list_imports.Rd diff --git a/NAMESPACE b/NAMESPACE index e0fae85..a8344ce 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,3 +3,4 @@ export(fetch_available_archives) export(fetch_available_packages) export(list_depends) +export(list_imports) diff --git a/R/list_imports.R b/R/list_imports.R new file mode 100644 index 0000000..3afcb11 --- /dev/null +++ b/R/list_imports.R @@ -0,0 +1,17 @@ + +#' Find all the packages the current project directly includes and their +#' versions. +#' +#' @return A data frame with the directly required packages +#' @export +list_imports <- function() { + packages <- sort(unique(renv::dependencies(progress = FALSE)$Package)) + all_packages <- installed.packages() + all_packages <- as.data.frame(all_packages) + all_packages <- all_packages[all_packages$Package %in% packages,] + packages <- data.frame( + package = all_packages$Package, + version = all_packages$Version + ) + return(packages) +} \ No newline at end of file diff --git a/man/list_imports.Rd b/man/list_imports.Rd new file mode 100644 index 0000000..1d983d8 --- /dev/null +++ b/man/list_imports.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/list_imports.R +\name{list_imports} +\alias{list_imports} +\title{Find all the packages the current project directly includes and their +versions.} +\usage{ +list_imports() +} +\value{ +A data frame with the directly required packages +} +\description{ +Find all the packages the current project directly includes and their +versions. +}