r-gregmisc / gtools

Functions to assist in R programming
25 stars 6 forks source link

gtools::checkRVersion not detecting R 4.0.0 #5

Closed AndreMikulec closed 3 years ago

AndreMikulec commented 4 years ago

Gregory R. Warnes,

checkRVersion is not detecting R 4.0.0 (that has just been released.)

> gtools::checkRVersion
The latest version of R is installed: 3.6.3

This new page exists.

https://cran.r-project.org/src/base/R-4/
Index of /src/base/R-4
[ICO]   Name    Last modified   Size    Description
[PARENTDIR] Parent Directory        -    
[   ]   R-4.0.0.tar.gz  2020-04-24 09:05    32M  
Apache Server at cran.r-project.org Port 443

The case may be to change from . . .

    page3 <- scan(file="https://cran.r-project.org/src/base/R-3",
                  what="", quiet=TRUE)

    combined <- c(page2, page3)

to . . .

    page3 <- scan(file="https://cran.r-project.org/src/base/R-3",
                  what="", quiet=TRUE)

    page4 <- scan(file="https://cran.r-project.org/src/base/R-4",
                  what="", quiet=TRUE)

    combined <- c(page2, page3, page4)
warnes commented 4 years ago

Thanks for reporting this.

AndreMikulec commented 4 years ago

Greg,

If anyone cares, I have been using this new anonymous function in my Rprofile.site file. This function is based off of the code in gtools::checkRVersion. This new function is very nice.

if (interactive()) {
    # gtools__checkRVersion
    (function (quiet = FALSE) {
        page2 <- scan(file = "https://cran.r-project.org/src/base/R-2",
            what = "", quiet = TRUE)
        page3 <- scan(file = "https://cran.r-project.org/src/base/R-3",
            what = "", quiet = TRUE)
        # NEW BY ANDRE
        page4 <- scan(file = "https://cran.r-project.org/src/base/R-4",
            what = "", quiet = TRUE)
        combined <- c(page2, page3, page4)
        matches <- grep("R-[0-9]\\.[0-9]+\\.[0-9]+", combined, value = TRUE)
        versionList <- gsub("^.*R-([0-9].[0-9]+.[0-9]+).*$", "\\1",
            matches)
        versionList <- numeric_version(versionList)

        banner <- function(Message, software = "Current") {
          if(software == "Newer") {
            writeLines("********************************************")
            writeLines("   ***   ***   ***   ***   ***   ***   ***  ")
            writeLines("***   ***   ***   ***   ***   ***   ***   **")
          }
          writeLines("********************************************")
          writeLines(Message)
          writeLines(Message)
          writeLines("********************************************")
          if(software == "Newer") {
            writeLines("***   ***   ***   ***   ***   ***   ***   **")
            writeLines("   ***   ***   ***   ***   ***   ***   ***  ")
            writeLines("********************************************")
          }

        }

        if (max(versionList) > getRversion()) {
            if (!quiet) {
                LATESTVERSION <- paste0("A newer version of R is now available: ", as.character(max(versionList)))
                banner(LATESTVERSION, software = "Newer")
            }
            invisible(max(versionList))
        }
        else {
            if (!quiet) {
                LATESTVERSION <- paste0("The latest version of R is installed: ", as.character(max(versionList)))
                banner(LATESTVERSION)
            }
            invisible(NULL)
        }
    })()
    # OTHER STUFF
}

If a new version of R exists, output will be displayed like this:

********************************************
   ***   ***   ***   ***   ***   ***   ***
***   ***   ***   ***   ***   ***   ***   **
********************************************
A newer version of R is now available: 4.0.3
A newer version of R is now available: 4.0.3
********************************************
***   ***   ***   ***   ***   ***   ***   **
   ***   ***   ***   ***   ***   ***   ***
********************************************
warnes commented 3 years ago

I've just submitted gtools 3.9.0 to CRAN, which includes the fix to recognize R version 4 and later.