Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R, list all packages and versions used in a markdown file

Tags:

r

r-markdown

Hi I'm using R and R studio. Is there a way I can have my R markdown file list all the packages and their respected versions at the end of the documents? thanks! For example,

---
title: "test"
output: pdf_document
---

## R Markdown

```{r cars}
library(ggplot2)
library(gplots)
summary(cars)
```
like image 388
Ahdee Avatar asked Dec 18 '22 17:12

Ahdee


1 Answers

You can get the names of loaded non-base packages with names(sessionInfo()$otherPkgs), so maybe something like this:

---
title: "test"
output: pdf_document
---

## R Markdown

```{r}
library(ggplot2)
library(data.table)
summary(cars)
``` 

```{r}
installed.packages()[names(sessionInfo()$otherPkgs), "Version"]
``` 

enter image description here

like image 160
nrussell Avatar answered Jan 07 '23 00:01

nrussell