开发者

Setting proxy on .Rprofile on OSX fails

开发者 https://www.devze.com 2023-02-24 17:11 出处:网络
In order to access CRAN packages from within R on OSX I\'ve been using Sys.setenv(http_proxy=\"http://blah_blah:1234/\")

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 开发者_如何学Cfile 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"))


Couldn't you just use .First ?

http://cran.r-project.org/doc/manuals/R-intro.html#Customizing-the-environment


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


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

精彩评论

暂无评论...
验证码 换一张
取 消