How to set proxy settings for R (Mac OSX)
I run R behind a firewall, and found it tricky to set the proxy settings for R so that I could directly install packages, access outside data using load(url()), etc. The solution lies in the http_proxy environment variable. Here is how to set it up:
Create a text file called .Rprofile in your home directory (on Mac OSX, this is ~ or /Users/myuser/). This text file should have the following line in it:
Sys.setenv(http_proxy=”http://username:password@tcdproxy.tcd.ie:8080″)
substituting your own username, password, and proxy server and port settings of course.
It seems that running this from R before you need it does not work, since I have heard reports that it only works if you run it as the first command in R when you start a new R session. By setting this up in your ~/.Rprofile you avoid having to retype it each time you start R, as well as making sure that this command is run at startup.
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
March 19th, 2009 at 11:01 am
putting
http_proxy=http://username:password@tcdproxy.tcd.ie:8080
in ~/.Renviron will work too.
October 21st, 2010 at 1:40 pm
But what if I want to use my Notebook sometimes behind a firewall and sometimes don’t?
I find it difficult to change invisible files often.
December 13th, 2010 at 8:40 am
Alex: To undo the proxy setting, I thought that
Sys.unsetenv(“http_proxy”) would work, but it doesn’t.
January 10th, 2011 at 4:06 pm
How to set a proxy for R under Windows the easy way (for a proxy that requires authentication):
I tried to implement the original suggestion under Windows, but didn’t succeed (although I’m sure the profile file was loaded). However, here is a much simpler way (by courtesy of folks from the TCD Stats Department):
Right-click on the shortcut that is used to open R. Click on ‘Properties’. In the ‘Target’ box, where it says “…\Rgui.exe”, simply add the following:
http_proxy=http://tcdproxy.tcd.ie:8080/ http_proxy_user=ask
Click Apply and OK.
This version also has the advantage that the user is prompted to type in the password once per session; thus, you don’t have to write it down anywhere as clear text.
January 25th, 2011 at 2:20 pm
hi, i try this and it woks perfect :
Sys.setenv(ftp_proxy=”username:password@tcdproxy.tcd.ie:8080″)
June 30th, 2011 at 7:32 am
Hi, I got it working, but now I’m using my computer in different location so I would need to take the proxy settings off. I simply deleted the .Rprofile but it didn’t help. What should I do? I’m using a Mac.
March 20th, 2012 at 2:55 pm
Thank you !
Don’t know why R doesn’t look at the http_proxy env variable…