[R] Test internet presence

(Ted Harding) Ted.Harding at nessie.mcc.ac.uk
Tue Sep 12 02:28:21 CEST 2006


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,
Ted.

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



More information about the R-help mailing list