1

Sys.info() gives system information, and we can see the operating system and its version with

e.g.

Sys.info()['sysname']
 sysname 
"Darwin"

but how can we see precisely the macOS name (e.g. Catalina, Mojave, Big Sur etc)?

stevec
  • 41,291
  • 27
  • 223
  • 311

1 Answers1

2

R itself does that in utils:::.osVersion() which (in R 4.0.2) looks (for the part you care about) like

       "Darwin" = {
           ver <- readLines("/System/Library/CoreServices/SystemVersion.plist")
           ind <- grep("ProductUserVisibleVersion", ver)
           ver <- ver[ind + 1L]
           ver <- sub(".*<string>", "", ver)
           ver <- sub("</string>$", "", ver)
           ver1 <- strsplit(ver, ".", fixed = TRUE)[[1L]][2L]
           sprintf("%s %s %s",
                   ifelse(as.numeric(ver1) < 12, "OS X", "macOS"),
                   switch(ver1,
                          ## 10.6 is earliest that can be installed
                          "6" = "Snow Leopard",
                          "7" = "Lion",
                          "8" = "Mountain Lion",
                          "9" = "Mavericks",
                          "10" = "Yosemite",
                          "11" = "El Capitan",
                          "12" = "Sierra",
                          "13" = "High Sierra",
                          "14" = "Mojave",
                          "15" = "Catalina",
                          ""), ver)
       },

It is defined in is defined in src/library/utils/R/sessionInfo.R; you can see the whole function with the other switch parts for other OSs there.

r-devel is doing some guessing around Big Sur:

           if(ver1[1L] == "10")
               sprintf("%s %s %s",
                       ifelse(as.numeric(ver2) < 12, "OS X", "macOS"),
                       switch(ver2,
                              ## 10.6 is earliest that can be installed
                              "6" = "Snow Leopard",
                              "7" = "Lion",
                              "8" = "Mountain Lion",
                              "9" = "Mavericks",
                              "10" = "Yosemite",
                              "11" = "El Capitan",
                              "12" = "Sierra",
                              "13" = "High Sierra",
                              "14" = "Mojave",
                              "15" = "Catalina",
                              "16" = "Big Sur", # probably not 10.16
                              ""),
                       ver)
           else
               sprintf("macOS %s %s",
                       switch(ver2,
                              "0" = "Big Sur",
                              ""),
                       ver)

The problem is actually hard. I was just the other day trying to find canonical Linux base distro names (such debian8, centos7, ...). Not that easy or standardized.

stevec
  • 41,291
  • 27
  • 223
  • 311
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725