Package sorting by date in RStudio pane

I regularly update a lot of packages via RStudio and want to see if changes impact current code or new features appeal

As a memory jog, it would be extremely useful if in the Packages pane there was also a sortable date column alongside the Version column

Or, failing that, is there a script version somewhere I could run

TIA

Point of clarification: do you want the date that you updated the package, or the date on which on the package was last updated?

the latter. I guess it is the first (of three!) dates in the DESCRIPTION file

I guess this should work:

devtools::session_info()$packages %>% 
   dplyr::arrange(desc(date))

         package *    version       date                              source
1          withr        2.0.0 2017-10-18    Github (jimhester/withr@a43df66)
2           glue   1.1.1.9000 2017-10-14     Github (tidyverse/glue@9846e72)
3     rstudioapi   0.7.0-9000 2017-10-14 Github (rstudio/rstudioapi@335f257)
4     data.table     1.10.4-1 2017-10-09                      CRAN (R 3.4.2)
5          rgdal       1.2-13 2017-10-07                      CRAN (R 3.4.2)
6          dplyr *      0.7.4 2017-09-28                      CRAN (R 3.4.2)
7           Rcpp      0.12.13 2017-09-28                      CRAN (R 3.4.2)
1 Like

@Ibusett +1 That would make a good snippet. Just looking at the function description it does not seem to be able to filter
out just those loaded (rather than base+attached as well). Is that correct? Sorting on package name for solelyloaded packages would be a boon

However, that is not quite what i'm after, which is viewing all packages on my system - not just those i have loaded. I can, of course, just look in the file directories but the ideal, for me, would have them sortable by date in the RStudio pane so that one click would lead me to their documentation

Yes, you're right. That is only valid for loaded packages.

This should be more in line with what you wish (obviously it does nothing to RStudio ..:slight_smile: , but I thought you were also interested in a "script" solution):

library(utils, quietly = T)
library(data.table)
#> Warning: package 'data.table' was built under R version 3.4.2
suppressPackageStartupMessages(library(dplyr, quietly = T))
#> Warning: package 'dplyr' was built under R version 3.4.2

get_pkginfo <- function(pkg){
  description <- utils::packageDescription(pkg)
  # get date
  if ("Date/Publication" %in% names(description)) {
    date <- as.Date(description$"Date/Publication")
  } else {
    if ("Date"  %in% names(description)) {
      date <- as.Date(description$Date)
    } else {
      if ("Built"  %in% names(description)) {
        date <- as.Date(stringr::str_split_fixed(description$Date, ";", 3)[2])
      }
    }
  }
  repo <- description$Repository
  
  # return info
  data.frame(Name    = pkg,
             Version = description$Version,
             Repo    = ifelse(!is.null(repo), repo, NA),
             date    = date)
}

# get list of installed packages
pkgs <- as.character(installed.packages()[,1])

# get some info
pkginfo <- lapply(pkgs, FUN = function(x) get_pkginfo(x)) %>% 
  data.table::rbindlist() %>% 
  arrange(desc(date))

head(pkginfo)
#>            Name     Version Repo       date
#> 1         purrr       0.2.4 CRAN 2017-10-18
#> 2 RcppArmadillo 0.8.100.1.0 CRAN 2017-10-11
#> 3    tidyselect       0.2.2 CRAN 2017-10-10
#> 4    data.table    1.10.4-1 CRAN 2017-10-09
#> 5         rgdal      1.2-13 CRAN 2017-10-07
#> 6          curl         3.0 CRAN 2017-10-06

summary(pkginfo)
#>            Name           Version      Repo          date           
#>  boot        :  2   3.4.1     : 15   CRAN:246   Min.   :2011-04-13  
#>  foreign     :  2   1.0.0     : 12   NA's: 67   1st Qu.:2016-08-05  
#>  Matrix      :  2   0.0.0.9000: 10              Median :2017-03-29  
#>  mgcv        :  2   0.2.0     :  9              Mean   :2016-11-03  
#>  abind       :  1   0.1.0     :  7              3rd Qu.:2017-07-23  
#>  addinmanager:  1   1.1.1     :  7              Max.   :2017-10-18  
#>  (Other)     :303   (Other)   :253              NA's   :59

Since in the description sometimes the "Date/Publication" field is not available, it tries also with the "Date" and the "Built" fields, in succession.

Still have 59 packages without dates, and double entries for four packages which I can't explain, but could be a good starting point.

HTH.

2 Likes

Thanks for going to so much trouble

No trouble at all. I find replying to questions of other people a good way to learn new things, so it's a win-win... Never knew about the existence of a packageDescription function, for example.

1 Like

Same with me and blog posts - hence the interest in new functions in packages

Have to say that devtools and utils have stacks of functions I knew nothing about

Just wanted to say thanks for this! Helped me locate packages that have messed up an app!