[R] Test internet presence
Gregor Gorjanc
gregor.gorjanc at bfro.uni-lj.si
Tue Sep 12 00:59:31 CEST 2006
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.
More information about the R-help
mailing list