Re: [R] Test internet presence

From: Ted Harding <>
Date: Tue 12 Sep 2006 - 00:28:21 GMT

On 11-Sep-06 Gregor Gorjanc wrote:
> Thank you. Your solution is usable but unfortunatelly not portable to
> Windows. I would like to use this test in package check, which can
> include also windows OS.

Now that I think about it (should have done that earlier), you can use the value of .Platform$OS.type (either "unix" or "windows") to determine the OS type, and also the value of the "system" command to see what is sent back from the "ping" command.

Then the R command to ping a remote host once would be

  system("ping -c 1 <remote host>") for "unix"

  system("ping -n 1 <remote host>") for "windows"     (at any rate for the DOS-based ping in Windows 98).

However, the returned value of "system" (which consists of the output of the ping commmand) is a multi-line value, and is different between Unix and Windows

So to distinguish between success and failure, you would have to do some slightly complex parsing of the output returned by "system", and evaluate it differently according to operating system. And the latter may vary between different versions of the OS ... Maybe it wasn't such a good suggestion after all.

However, since separate versions of your package would be compiled for Unix-like systems and for Windows, perhaps a way round such differences is to write a different script for each one (shell script as before for Unix, "batch file" for Windows), crafted so as to return identical results in the two cases for success, and for failure.

Best wishes,

E-Mail: (Ted Harding) <> Fax-to-email: +44 (0)870 094 0861
Date: 12-Sep-06                                       Time: 01:28:15
------------------------------ XFMail ------------------------------

______________________________________________ mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Tue Sep 12 16:08:55 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 12 Sep 2006 - 06:30:08 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.