R_usr
R_usr

Reputation: 75

Setting proxy on .Rprofile on OSX fails

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"))

Upvotes: 0

Views: 1654

Answers (3)

Sam Inverso
Sam Inverso

Reputation: 441

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

Upvotes: 1

R_usr
R_usr

Reputation: 75

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.

Upvotes: 0

Related Questions