Re: [R] Test internet presence

From: Gregor Gorjanc <gregor.gorjanc_at_bfro.uni-lj.si>
Date: Mon 11 Sep 2006 - 22:59:31 GMT

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.

> On 11-Sep-06 Ted Harding wrote:

>> On 11-Sep-06 Gregor Gorjanc wrote:
>>> It seems that 'internal' method was used (I use R 2.3.1 under
>>> Linux) as indicated in help page of download.file. I could
>>> use wget or lynx methods, but these two must be available,
>>> so this is not really portable. Are there any other options
>>> for testing internet access? I am thinking that this might be
>>> more relevant for R-devel. I will wait a bit
>>> before moving there.
>>>
>>> --
>>> Lep pozdrav / With regards,
>>> Gregor Gorjanc
>> Hi Gregor,
>> Since you are using Linux, I think you should ask R to delegate
>> the test to the system.
>>
>> If you have a script, in executable file ("755") say "test.inet.sh",
>> which says something like
> 
>   if ping -c 1 <something> ; then
>       export NET_UP="YES"
>     else
>       export NETP_UP="NO"
>   fi
> 

>> where "<something>" is the IP address or name of an external host
>> which responds to 'ping' (some will not, depending on their firewall
>> settings), then you can use on R:
>>
>>>>> system("test.inet")
>>>>> if( sys.getenv(NET_UP") == "YES" ) { ... } else { ... }
> 
> system("test.inet.sh")
> if( sys.getenv("NET_UP") == "YES" ) { ... } else { ... }
> 

>> For example (nothing to do with R, but shows the principle),
>> I have the following script to set my system time and hardware
>> clock from whichever one of 3 NTP servers is willing to respond:
>>
>> if /bin/ping -c 1 ntp0.zen.co.uk ; then
>> export NETTIME="/usr/sbin/ntpdate -u ntp0.zen.co.uk"
>> elif /bin/ping -c 1 ntp2b.mcc.ac.uk ; then
>> export NETTIME="/usr/sbin/ntpdate -u ntp2b.mcc.ac.uk"
>> elif /bin/ping -c 1 ntp2c.mcc.ac.uk ; then
>> export NETTIME="/usr/sbin/ntpdate -u ntp2c.mcc.ac.uk"
>> else
>> export NETTIME=""
>> fi
>> if [ "$NETTIME" != "" ] ; then
>> sleep 1
>> sleep 1
>> $NETTIME
>> /sbin/clock -u -w
>> date
>> fi
>>
>>
>> which also illustrates how to allow for the possibility that
>> the "default" server might not be responding at the time, so
>> it has 2 fallback servers.
-- 
Lep pozdrav / With regards,
    Gregor Gorjanc

----------------------------------------------------------------------
University of Ljubljana     PhD student
Biotechnical Faculty
Zootechnical Department     URI: http://www.bfro.uni-lj.si/MR/ggorjan
Groblje 3                   mail: gregor.gorjanc <at> bfro.uni-lj.si

SI-1230 Domzale             tel: +386 (0)1 72 17 861
Slovenia, Europe            fax: +386 (0)1 72 17 888

----------------------------------------------------------------------
"One must learn by doing the thing; for though you think you know it,
 you have no certainty until you try." Sophocles ~ 450 B.C.

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Tue Sep 12 15:24:59 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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.