2

You can check whether you are running OS X using Sys.info()["sysname"] == "Darwin".

On Windows, finer control is possible by checking for specific versions of the OS using utils::win.version().

How do you check the version of OS X? (I can't find a mac.version or osx.version function. There are some low-level OS commands for finding the version, but I'm not aware of any R wrapper.)

Do Sys.info()["release"] or system("uname --kernel-release", intern = TRUE) return anything useful? (I don't have a machine to check.)

Community
  • 1
  • 1
Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
  • I am not on OS X, but doesn't `R.version$os` provide useful information? ([source](https://stat.ethz.ch/R-manual/R-devel/library/base/html/Version.html)) –  Sep 07 '15 at 07:57
  • I only know about Linux and Windows. There, `R.version$system` gives information on the OS in general and `sessionInfo()$running` provides details concerning the version of the OS that is used. – RHertel Sep 07 '15 at 08:01
  • doesnt `Sys.info()` already tells you the version name in `version` field. In windows the value in the field `version` and the output of `win.version` is same. it has also clubbed sysname and release name in the output that is it. – Dhawal Kapil Sep 07 '15 at 08:06
  • @Pascal The help page for `R.version` explicitly states "Do not use R.version$os to test the platform the code is running on". – Richie Cotton Sep 07 '15 at 08:12
  • @RichieCotton It also says "## a good way to detect OS X: if(grepl("^darwin", R.version$os)) message("running on OS X")" –  Sep 07 '15 at 08:13
  • `.Platform` reports the Os type, but not the version number. – Richie Cotton Sep 07 '15 at 08:13
  • @DhawalKapil `Sys.info()["release"]` looks promising. I don't have access to a mac, so if you can post some examples of what it returns under OS X, that's worth at least an upvote. – Richie Cotton Sep 07 '15 at 08:16

4 Answers4

2

Depending on what you actually want, I would use:

system("uname -r")
14.5.0

or

system("uname -s")
Darwin

or

system("uname -v")
Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53 PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
2

Sys.info()["sysname"] returns "Darwin" on Mac OS X.

Sys.info()["release"] tells you what version of Mac OS X. For example, "13.4.0" is Mac OS X 10.9.5.

There probably is no need to do a system() call: Sys.info()["version"] seems to return exactly the same as system("uname -v"). And this version really combines different pieces of information and is not convenient for just checking whether or not you're running on Mac. For example

> Sys.info()["version"]
version
"Darwin Kernel Version 13.4.0: Wed Mar 16 09:03:04 PDT 2015; root:xnu-2422.115.14~1/RELEASE_X86_64"
WhiteViking
  • 3,146
  • 1
  • 19
  • 22
1

Use Sys.info() to get most of the information about the current platform:

Example:

osname_version<-c(paste(" System: ",Sys.info()[['sysname']],
                      "\nVersion: ",Sys.info()[['version']],
                      "\nRelease: ",Sys.info()[['release']],
                      "\nMachine: ",Sys.info()[['machine']]))
cat(osname_version,"\n")

Result:

 System:  Linux 
Version:  #1 SMP Fri Sep 2 15:45:09 CEST 2011 
Release:  2.6.32.46 
Machine:  i686 

More Information: https://stat.ethz.ch/R-manual/R-devel/library/base/html/Sys.info.html

l'L'l
  • 44,951
  • 10
  • 95
  • 146
0

Since Sys.info() gives the kernel version rather than the product version, I've opted for using sw_vers instead.

as.numeric_version(system("sw_vers -productVersion", intern = TRUE))
Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
  • Nicer wrappers to this now in the devel version of `assertive.reflection`. https://bitbucket.org/richierocks/assertive.reflection – Richie Cotton Sep 07 '15 at 11:07