R: source() cannot open the connection, status was 'Couldn't resolve host name'

1k Views Asked by At

I am trying to source a script from my github repo containing functions I use often. So I have that line at the beginning of my script:

source("https://github.com/jogaudard/common/blob/master/fun-fluxes.R")

In RStudio it returns (same with R in the terminal)

Error in source("https://github.com/jogaudard/common/blob/master/fun-fluxes.R") : 
https://github.com/jogaudard/common/blob/master/fun-fluxes.R:6:1: unexpected '<'
5: 
6: <
   ^

In an online R editor I got

Error in file(filename, "r", encoding = encoding) : 
cannot open the connection to 'https://github.com/jogaudard/common/blob/master/fun-fluxes.R'
Calls: source -> file
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
URL 'https://github.com/jogaudard/common/blob/master/fun-fluxes.R': status was 'Couldn't resolve host name'
Execution halted

I tried with other scripts. I get the same error with anything that is online. source() is working fine with scripts in local (both in the same directory or somewhere else).

It happened since I installed a package that messed a bit with curl. So I thought that might be the issue. But when I tried from another computer I got the same error.

Both computers have R version 3.6.3 on Ubuntu 18.04.5 LTS

I am honestly lost. Cannot find any similar issues anywhere.

1

There are 1 best solutions below

1
On BEST ANSWER

You are sourcing a file with html markup and R considers that markup (correctly) to be syntax errors. Use source("https://raw.githubusercontent.com/jogaudard/common/master/fun-fluxes.R") to source the "raw" file.

Your issue with the online R services is a red herring. If you need someone to look into that, you should provide a URL for the service.