R 3.5.0 Package Update
After our IT colleagues updated R to version 3.5.0 I found that I have many packages duplicated between the system library and my user library. This short piece of code lists all packages with their version for all libraries. It helps identify those that can be removed from the user library or updated.
1## assess user and system packages
2##
3
4library(purrr)
5library(dplyr)
6
7df.all <- as.data.frame(installed.packages()[,c(1:4, 16)], stringsAsFactors = FALSE)
8df.split <- split.data.frame(df.all, df.all$LibPath)
9df.wide <- reduce(df.split, full_join, by = 'Package')
10names(df.wide) <- c('Package', paste0(rep(c('libpath_', 'version_', 'priority_', 'built_'), length(df.split)), rep(seq(length(df.split)), each = 4)))
11
12## in library 2 but not 1
13df.user_lib <- df.wide %>%
14 filter(is.na(libpath_1) & !is.na(libpath_2))
15
16## in both library 1 and 2
17df.libs12 <- df.wide %>%
18 filter(!is.na(libpath_1) & !is.na(libpath_2))