Skip to content

source and localhost

6 messages · Thomas.Bock at ptb.de, Uwe Ligges, Brian Ripley +2 more

#
Dear List,

I have problems with the function source() using a
url of the kind:

http://localhost:5984/path/fn.R

I receive

Fehler in file(file, "r", encoding = encoding) : 
  kann Verbindung nicht ?ffnen
Zus?tzlich: Warnmeldung:
In file(file, "r", encoding = encoding) :
  ?ffnen fehlgeschlagen: HTTP Status war '502 cannotconnect'

The url itself is ok since I can:
- use a browser
- use curl
- use download.file() function
- use getURL() (out of Duncans RCurl)

furthermore it works, when I use the full host + domain name.
So I think it is about dns stuff. I get a nice:
[1] "localhost, 127.0.0.1"

and work on 32bit opensuse 11.4 with 
R version 2.13.0 (2011-04-13)

Can someone give me a hint?
Best regards
Thomas
#
On 20.05.2011 17:22, Thomas.Bock at ptb.de wrote:
Does

con <- url("http://localhost:5984/path/fn.R")
source(url)
close(con)

work for you?

Please read ?source carefully and note it uses a file() connection as 
the default unless you specify another connection explicitly..

Uwe Ligges
#
On Fri, 20 May 2011, Uwe Ligges wrote:

            
Correct, but ?file says

      For ?file? the description is a path to the file to be opened or a
      complete URL (when it is the same as calling ?url?), ...

so this works in principle (and in practice for me: 
source("http://www.stats.ox.ac.uk/~ripley/APTS2010/slice.R") ). So the 
issue is something peculiar to the URL. Maybe try download.file on it 
with options(internet.info=0) to get maximal info.

  
    
#
No; I have tested it already.
the man page says:

 file: a connection or a character string giving the pathname of the
          file or URL to read from.  ...

The point is that it works with:
 
source("http://host.domain.de: .../.../fn.R")

How can I specify another connection explicitly? With url, isn't it?
http://www.R-project.org/posting-guide.html
#
Thomas,

your example works with R-2.13.0 and Apache running on
Gentoo. You may try to use "http://127.0.0.1:5984/path/fn.R",
just to exclude that this problem has anything to do with 
name resolution.

Best

Hugo
#
"localhost" is the computer you are working at, and the ip assigned to the 
loob-back interface.  This is normally used for testing networking interfaces.   
That being so, simply using the path to the file on your machine, e.g. 
"/home/<username>/data/somedata.csv" should work much better.  

JWD