How to programmatically check if the current R installation is the newest?

How to check from level R if the current installation of R is the newest? Finding the version of installed R is easy, but how do you check what the latest version number is? Is such information available through CRAN?

+4
source share
2 answers

A quick search on my favorite search engine found this post from Yihui Xie , which I turned into a function:

checkRversion <- function(){ x = readLines("http://cran.r-project.org/sources.html") # the version number is in the next line of 'The latest release' rls = x[grep("latest release", x) + 1L] newver = gsub("(.*R-|\\.tar\\.gz.*)", "", rls) oldver = paste(getRversion(), collapse = ".") # new version available? message("Installed version: ", oldver) message("Latest version: ", newver) compareVersion(newver, oldver) } 

Using:

 checkRversion() Installed version: 3.0.1 Latest version: 3.0.1 [1] 0 
+5
source

You can use the gtools approach.

The code is similar to the code in Andrie's answer, but uses the /src/base/R folder explicitly, not the sources.html file, so it is potentially more reliable because it relies on actual executables.

The small problem is that gtools hardcoded to the folder name, so their code is β€œas is” incorrect, but I really like the idea, so I updated it to iterate over the available CRAN URLs and find the last one:

 checkRVersion <- function (quiet = FALSE) { baseUrl <- "http://cran.r-project.org/src/base/R-" majorVersion <- 3 repeat { url <- paste(baseUrl, majorVersion, sep = "") if (url.exists(url)) { majorVersion <- majorVersion + 1 } else { break } } url <- paste(baseUrl, (majorVersion-1), sep = "") page <- scan(file = url, what = "", quiet = TRUE) matches <- grep("R-[0-9]\\.[0-9]+\\.[0-9]+", page, value = TRUE) versionList <- gsub("^.*R-([0-9].[0-9]+.[0-9]+).*$", "\\1", matches) versionList <- numeric_version(versionList) if (max(versionList) > getRversion()) { if (!quiet) { cat("A newer version of R is now available: ") cat(as.character(max(versionList))) cat("\n") } invisible(max(versionList)) } else { if (!quiet) { cat("The latest version of R is installed: ") cat(as.character(max(versionList))) cat("\n") } invisible(NULL) } } 
+3
source

Source: https://habr.com/ru/post/1489882/


All Articles