[R] windows vs. linux code

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Feb 26 19:18:36 CET 2009


On Thu, 26 Feb 2009, Paul Gilbert wrote:

> Gabor Grothendieck wrote:
> ....
>> Try
>> 
>> if (.Platform$OS.type == "windows") ... else ...
>
> Gabor has suggested what I think is the best way to do this check, but in my 
> experience, if you are doing this check then you are almost certainly missing 
> some feature of R that will let you avoid doing it.
>
> For graphs, dev.new() has been mentioned.  I would be curious to know when 
> people find it necessary to do this check, other than to issue a system() 
> command for some very specialized local system reason (i.e. something that 
> would never be used in a package and rarely in code run on different 
> computers - not just different OSs).

Grep-ing the R and package sources is informative.

One place that such a test is needed is for system/shell differences, 
and the fact that some Windows commands need \ as the file separator 
(and some need / or shell-specific quoting).  Quite a few packages are 
calling e.g. gs (where the name is platform-dependent).

Some packages seem to treat tk differently by platform, but that seems 
to me to be largely a legacy of Tk 8.4: 8.5 is more portable.

But many uses in packages are no longer necessary, e.g. flush.console 
exists everywhere, and R 2.9.0 will have an unzip() function.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list