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:


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.

AddThis Social Bookmark Button
  • Will



    in ~/.Renviron will work too.

  • alex

    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.

  • Alex: To undo the proxy setting, I thought that

    Sys.unsetenv(“http_proxy”) would work, but it doesn’t.

  • nada-surfer

    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_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.

  • antonio81

    hi, i try this and it woks perfect :

  • Nops

    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.

  • Thank you !
    Don’t know why R doesn’t look at the http_proxy env variable…