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) } }
source share