I'm working on a package that needs to run slightly differently depending on different operating systems, and now versions of OS by the looks.
I'm wondering what the best way to check for different OS versions is?
I know that I can find some System information using Sys.info() and various combinations of the output from that. Is this the best (most reliable) way to get the OS version? I'm especially interested in detecting when a machine is running macOS Monterey. It seems that Sys.info()["release"] gives "21.x.x" for macOS Monterey, and "20.x.x" for Big Sur, but I have limited access to macOS, so it's difficult for me to test this.
(FWIW this is not the same as the OS that R was compiled for, which is typically older, that is in R.Version()$os and it might be missing the trailing zero versions, so on arm64 mac and R 4.1.x it is just darwin20.)
sessionInfo() is not reliable because if the R version is older than the macOS version you are running it on, it typically gives wrong results. E.g. these are for the same OS, and they are all mostly wrong, maybe you can consider the last one to be correct: