3

Possible Duplicate:
R: determine if a script is running in Windows or Linux

How can an R script determine what platform it's running on? I'm using R 2.10.1, sometimes on Windows, sometimes on Linux. I would prefer a built-in function over filesystem taxonomy. I've already searched the index of the base package for anything with "os" or "platform" in the description — no dice there, alas.

Community
  • 1
  • 1
Esteis
  • 4,669
  • 2
  • 29
  • 45
  • This is fairly [redundant with this previous question](http://stackoverflow.com/questions/2096473/r-determine-if-a-script-is-running-in-windows-or-linux). Not that I have a problem with redundancy. Not that I have a problem with redundancy. – JD Long Oct 13 '10 at 12:38

2 Answers2

9

Alternatives to R.version()$os are .Platform$OS.type and R.Version()$platform. See ?.Platform for further info. Note that Sys.info() is not implemented on all platforms, but does give the key information on which platform R is running whereas the others give info on the platform under which R was built.

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453
4

You can use R.Version()$os

Greg
  • 11,564
  • 5
  • 41
  • 27
  • 3
    Ah, excellent, that works. It has slightly different angle, though, as it returns "mingw32" instead of "windows", although the two usually come together. I've also just discovered Sys.info(), which seems to have been designed for my question: it returns a list with inter alia sysname = "Windows", release = "XP", etc. Thanks for your reply! – Esteis Oct 12 '10 at 23:49