6

I have the need to check logically if a computer's operating system is Solaris. In other words I need a way to check if the operating system is Solaris, if so return TRUE, if not return FALSE. I can easily check if an OS is Windows, Mac, Linux because I have access to these systems what type (e.g., "unix", "windows") to search for as this info is commonly google-able. Something along the lines of:

.Platform$OS.type == "unix"
.Platform$OS.type == "windows"

works and there are other approaches well documented on SO (e.g., Sys.info()["sysname"] == "Windows"). In my search of SO and Google I was led to many questions regarding Windows, Mac, Linux but no way to specifically to determine if the OS is Solaris. For instance this link, which leads to other similar questions it duplicates, addresses determining the OS but not a logical check if Solaris.

How to check the OS within R

How can I programmatically determine if a computer's OS is Solaris?

I may need to be more specific about what forms os Solaris I'm interested in (I'm not sure because I know very little about the OS). Of particular interest are the Solaris systems used in CRAN checks:

  1. r-patched-solaris-x86
  2. r-patched-solaris-sparc
Community
  • 1
  • 1
Tyler Rinker
  • 108,132
  • 65
  • 322
  • 519

1 Answers1

11

Digging into the C code that Sys.info uses, it ends up with a call to sys/utsname.h, which should be defined for most Unix-like systems (and is indeed part of the standard).

Looking at this website, it seems like Solaris uses SunOS as the utsname. Here is a copy just in case that link dies:

The utsname macro
We've already seen one macro in use on a Solaris 2 system, utsname. 
As a refresher, here is how we called the utsname macro ...
Figure 12-1 Using the utsname macro

...
utsname:        sys  SunOS 

Also, the Wikipedia article on uname clearly states that the system name for all Solaris systems is SunOS.

So, just for completeness, you could easily grep for this in a function:

is.solaris<-function()
  grepl('SunOS',Sys.info()['sysname'])
nograpes
  • 18,623
  • 1
  • 44
  • 67
  • I think that's it but have no way to test. I'll see if I can get Solaris for Virtual box. – Tyler Rinker May 24 '14 at 03:08
  • 4
    I have Solaris 11 on VirtualBox and can confirm that `Sys.info()['sysname']` returns `"SunOS"` – Ben May 24 '14 at 05:00
  • The string used in the CRAN description (http://cran.r-project.org/web/checks/check_flavors.html) appears to be part of `R.Version()$platform`. The documentation describes that as being " A triplet of the form CPU-VENDOR-OS, as determined by the configure script.". I wonder if there's some other way to access the vendor piece. – hadley May 26 '14 at 02:17
  • @Ben I looked for your contact info to discuss an issue of list but couldn't find it. If you could email me (see [qdap maintainer](http://cran.r-project.org/web/packages/qdapTools/index.html) info) I'd appreciate it. I built Solaris 11 on virtual box on a Win 7 machine but can't get R up an running. Any guidance on how you did it would be most appreciated. – Tyler Rinker May 27 '14 at 12:16
  • Hi Tyler, I've posted details [here](http://stackoverflow.com/a/24094964/1036500) ([this is me](http://faculty.washington.edu/bmarwick/)) – Ben Jun 07 '14 at 07:41