8

How can I produce a list of packages that need an update, i.e. a table with package name, version currently installed and version available at the repository?

I have tried to hack packageStatus(), installed.packages(), update.packages() but I am not able to force these functions to produce the desired output.

Note that I don't want to actually update these packages; I just want to see the mentioned list.

smci
  • 32,567
  • 20
  • 113
  • 146
Tomas
  • 57,621
  • 49
  • 238
  • 373

2 Answers2

11

Take a look at old.packages(). on my system I have:

R> old.packages()
              Package         LibPath                                   Installed   Built   ReposVer    Repository                           
bnlearn       "bnlearn"       "/home/gavin/R/build/3.0-patched/library" "3.4"       "3.0.2" "3.5"       "http://cran.rstudio.com/src/contrib"
deldir        "deldir"        "/home/gavin/R/build/3.0-patched/library" "0.1-4"     "3.0.2" "0.1-5"     "http://cran.rstudio.com/src/contrib"
devtools      "devtools"      "/home/gavin/R/build/3.0-patched/library" "1.3"       "3.0.2" "1.4.1"     "http://cran.rstudio.com/src/contrib"
digest        "digest"        "/home/gavin/R/build/3.0-patched/library" "0.6.3"     "3.0.2" "0.6.4"     "http://cran.rstudio.com/src/contrib"
extrafont     "extrafont"     "/home/gavin/R/build/3.0-patched/library" "0.15"      "3.0.2" "0.16"      "http://cran.rstudio.com/src/contrib"
forecast      "forecast"      "/home/gavin/R/build/3.0-patched/library" "4.8"       "3.0.2" "5.1"       "http://cran.rstudio.com/src/contrib"
foreign       "foreign"       "/home/gavin/R/build/3.0-patched/library" "0.8-57"    "3.0.2" "0.8-59"    "http://cran.rstudio.com/src/contrib"
Matrix        "Matrix"        "/home/gavin/R/build/3.0-patched/library" "1.1-0"     "3.0.2" "1.1-2"     "http://cran.rstudio.com/src/contrib"
matrixStats   "matrixStats"   "/home/gavin/R/build/3.0-patched/library" "0.8.12"    "3.0.2" "0.8.14"    "http://cran.rstudio.com/src/contrib"
mgcv          "mgcv"          "/home/gavin/R/build/3.0-patched/library" "1.7-27"    "3.0.2" "1.7-28"    "http://cran.rstudio.com/src/contrib"
mvtnorm       "mvtnorm"       "/home/gavin/R/build/3.0-patched/library" "0.9-9996"  "3.0.2" "0.9-9997"  "http://cran.rstudio.com/src/contrib"
party         "party"         "/home/gavin/R/build/3.0-patched/library" "1.0-11"    "3.0.2" "1.0-13"    "http://cran.rstudio.com/src/contrib"
R.methodsS3   "R.methodsS3"   "/home/gavin/R/build/3.0-patched/library" "1.5.2"     "3.0.2" "1.6.1"     "http://cran.rstudio.com/src/contrib"
raster        "raster"        "/home/gavin/R/build/3.0-patched/library" "2.2-5"     "3.0.2" "2.2-12"    "http://cran.rstudio.com/src/contrib"
Rcpp          "Rcpp"          "/home/gavin/R/build/3.0-patched/library" "0.10.6"    "3.0.2" "0.11.0"    "http://cran.rstudio.com/src/contrib"
RcppArmadillo "RcppArmadillo" "/home/gavin/R/build/3.0-patched/library" "0.3.920.1" "3.0.2" "0.4.000.2" "http://cran.rstudio.com/src/contrib"
rgl           "rgl"           "/home/gavin/R/build/3.0-patched/library" "0.93.991"  "3.0.2" "0.93.996"  "http://cran.rstudio.com/src/contrib"
rpart         "rpart"         "/home/gavin/R/build/3.0-patched/library" "4.1-3"     "3.0.2" "4.1-5"     "http://cran.rstudio.com/src/contrib"
scatterplot3d "scatterplot3d" "/home/gavin/R/build/3.0-patched/library" "0.3-34"    "3.0.2" "0.3-35"    "http://cran.rstudio.com/src/contrib"
survival      "survival"      "/home/gavin/R/build/3.0-patched/library" "2.37-4"    "3.0.2" "2.37-7"    "http://cran.rstudio.com/src/contrib"

For your specific requirements:

R> old.packages()[, c("Package","Installed","ReposVer")]
              Package         Installed   ReposVer   
bnlearn       "bnlearn"       "3.4"       "3.5"      
deldir        "deldir"        "0.1-4"     "0.1-5"    
devtools      "devtools"      "1.3"       "1.4.1"    
digest        "digest"        "0.6.3"     "0.6.4"    
extrafont     "extrafont"     "0.15"      "0.16"     
forecast      "forecast"      "4.8"       "5.1"      
foreign       "foreign"       "0.8-57"    "0.8-59"   
Matrix        "Matrix"        "1.1-0"     "1.1-2"    
matrixStats   "matrixStats"   "0.8.12"    "0.8.14"   
mgcv          "mgcv"          "1.7-27"    "1.7-28"   
mvtnorm       "mvtnorm"       "0.9-9996"  "0.9-9997" 
party         "party"         "1.0-11"    "1.0-13"   
R.methodsS3   "R.methodsS3"   "1.5.2"     "1.6.1"    
raster        "raster"        "2.2-5"     "2.2-12"   
Rcpp          "Rcpp"          "0.10.6"    "0.11.0"   
RcppArmadillo "RcppArmadillo" "0.3.920.1" "0.4.000.2"
rgl           "rgl"           "0.93.991"  "0.93.996" 
rpart         "rpart"         "4.1-3"     "4.1-5"    
scatterplot3d "scatterplot3d" "0.3-34"    "0.3-35"   
survival      "survival"      "2.37-4"    "2.37-7" 
Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453
  • 1
    Beat you by eight seconds ;-) – Dirk Eddelbuettel Feb 18 '14 at 15:36
  • 1
    @DirkEddelbuettel Yeah, but my Answer is bigger :P – Gavin Simpson Feb 18 '14 at 15:37
  • 1
    But from an obviously invalid system as you shown an outdated Rcpp in use. – Dirk Eddelbuettel Feb 18 '14 at 15:38
  • Thanks! Or I can use shorter `old.packages()[, c("Installed","ReposVer")]`. – Tomas Feb 18 '14 at 15:39
  • Hi @Dirk! It's strange but I have seen Gavin's answer on the top and didn't notice yours until now, even though he has lower score :-) Going to credit you too :) – Tomas Feb 18 '14 at 15:40
  • @Dirk strange enough, it is sorted by votes yet your answer is at the bottom. – Tomas Feb 18 '14 at 15:41
  • It is funny Gavin and @Dirk how you compete, I can see it on [another](http://stackoverflow.com/q/9368900/684229) of my questions too :-) This time Gavin's answer won on being more detailed, despite the outdated Rcpp :-) – Tomas Feb 28 '14 at 09:45
  • @Tomas It's not intentional. It'd be pretty stupid to compete with Dirk on most R-related things. I would only knowingly do it if the question related to one of my packages :-) – Gavin Simpson Feb 28 '14 at 15:03
7

Are you aware of the function old.packages() ?

From help(update.packages):

 ‘old.packages’ indicates packages which have a (suitable) later 
 version on the repositories whereas ‘update.packages’ offers to
 download and install such packages.
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Dirk, thank you for the answer. OT: I would like to ask you as an MCMC guru, if you have any experience with running JAGS from R. I am struggling with bugs in both R2jags and runjags packages. But you are probably using some Rcpp magic instead? :-) – Tomas Feb 18 '14 at 15:48
  • @Tomas I think you should ask a new question for that. – Dirk Eddelbuettel Feb 18 '14 at 16:07
  • Dirk, I would love to, but I am afraid a question like "What is the best way to run JAGS" would be closed in less than 5 seconds :-) Let alone question like "Dirk, what are real gurus using" :-) – Tomas Feb 18 '14 at 20:43