Setting proxy on .Rprofile on OSX fails

1.6k Views Asked by At

In order to access CRAN packages from within R on OSX I've been using

Sys.setenv(http_proxy="http://blah_blah:1234/")

as the first command in the R GUI for a while, but would really like to set this proxy automatically.

I've tried unsuccessfully to get the same command to work in a .Rprofile file in ~/

I've also tried http_proxy="http://blah_blah:1234/", but this fails too.

The error I get when I try to view packages is a drop-down window that says:

Fetching Package List Failed
Please consult R Console output for details

The GUI then gives:

Error in read.dcf(file = tmpf) : Line starting '<head> ...' is malformed!

The .Rprofile file itself seems to be loading (checked using cat("my profile works\n"))

3

There are 3 best solutions below

1
On BEST ANSWER
0
On

I think I have managed to solve this using trial and error...

A combination of .First and Sys.setenv() works.

If anyone has any ideas I'd be interested to know why.

0
On

This thread appears first when searching for setting R proxy on OS X, so here's what I use in my .Rprofile:

Sys.setenv(http_proxy=system("networksetup -getwebproxy Ethernet | awk {'print $2'} | awk {'getline l2; getline l3; print \"http://\"l2\":\"l3'} | head -n 1",intern=TRUE))

Change Ethernet to Airport if necessary.

Credit for the awk part goes to Chealion