Package version control

One aspect of writing a manuscript that I find tedious is checking the versions of the R packages I used. So I wrote a small function to do this automatically.

get_version = function(package){
installed.packages() %>%
as_data_frame() %>%
filter(Package == package) %$%
paste(Package, "version", Version)

(I don’t use ​= as an assignment operator in my code, but the <- operator together with pipes tends to upset wordpress and it leaves out a chunk of code.)

This function will convert get_version("vegan") in my  rmarkdown file  to “vegan version 2.4-6” in the pdf. Problem solved (except that I still need to check the citation is up to date).

I can also grab the R version with gsub("(.*) \\(.*", "\\1", R.version.string), which gives “R version 3.4.4”.


About richard telford

Ecologist with interests in quantitative methods and palaeoenvironments
This entry was posted in R, Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s