How to select a CRAN mirror in R

274,854

Solution 1

You should either get a window with a list of repositories or a text menu with some options. But if that is not appearing, you can always specify the mirror from where to download the packages yourself by using repos parameter. By doing that, R will not ask you anymore about the repository. Example:

install.packages('RMySQL', repos='http://cran.us.r-project.org')

Here you have a list of mirrors for R.

Solution 2

Here is what I do, which is basically straight from the example(Startup) page:

## Default repo
local({r <- getOption("repos")
       r["CRAN"] <- "http://cran.r-project.org" 
       options(repos=r)
})

which is in ~/.Rprofile.

Edit: As it is now 2018, we can add that for the last few years the URL "https://cloud.r-project.org" has been preferable as it reflects a) https access and b) an "always-near-you" CDN.

Solution 3

I'm a fan of:

chooseCRANmirror()

Which will print the list of mirrors in the output (no worrying a popup window since you are running it from the terminal) and then you enter the number you want.

Solution 4

I use the ~/.Rprofile solution suggested by Dirk, but I just wanted to point out that

chooseCRANmirror(graphics=FALSE)

seems to be the sensible thing to do instead of

chooseCRANmirror(81)

, which may work, but which involves the magic number 81 (or maybe this is subtle way to promote tourism to 81 = UK (Bristol) :-) )

Solution 5

Repository selection screen cannot be shown on your system (OS X), since OS X no longer includes X11. R tries to show you the prompt through X11. Install X11 from http://xquartz.macosforge.org/landing/. Then run the install command. The repo selection prompt will be shown.

Share:
274,854

Related videos on Youtube

Jim Johnson
Author by

Jim Johnson

Updated on March 07, 2020

Comments

  • Jim Johnson
    Jim Johnson about 4 years

    I'm trying to install a package through the R prompt by doing the following:

    install.packages('RMySQL')
    

    But the output is as follows:

    --- Please select a CRAN mirror for use in this session ---
    

    And nothing else! I can't find a solution to this very basic problem. What am I supposed to type in order to select a CRAN mirror?

    EDIT:

    OS: Mac-OS X 10.6.8 R Version: 2.15.0

    • pyCthon
      pyCthon almost 12 years
      it should come up with a list of numbers from 1 - 100 coresponding to the mirror , try typing 84 and hit enter
    • pyCthon
      pyCthon almost 12 years
      also add what OS you are using , and which version of R
    • sayhey69
      sayhey69 almost 12 years
      Either a window should pop up with selections or a list of selections should appear in the console. Did you check for a separate window with choices? How are you running R?
    • Jim Johnson
      Jim Johnson almost 12 years
      @pyCthon I typed 84, but nothing is returned.
    • Jim Johnson
      Jim Johnson almost 12 years
      @sayhey69 I'm simply running R by calling the prompt from my terminal. I just type in r, and the interpreter comes up. I've never had any separate windows popping up asking for choices.
    • sayhey69
      sayhey69 almost 12 years
      in that case the list of mirrors should appear in the console. fwiw 70 is the mirror at Berkeley that I use. What OS do you use? If you are using linux try sudo apt-get update.
    • tim
      tim almost 9 years
      it's because you need X windows to allow Rconsole can throw a graphical dialog... R should detect you don't have windowing, and fall back to printing a list and asking for input, but doesn't...
  • Jared
    Jared about 11 years
    Oops, do chooseCRANmirror(81) and it brings up a prompt for you to enter a number. All in the console.
  • Darren Cook
    Darren Cook almost 11 years
    Note: this doesn't appear to update either /etc/R/Rprofile.site or ~/.Rprofile. (So, it is not good for choosing an alternative old mirror that has disappeared. Better to edit the above files directly.)
  • Jared
    Jared almost 11 years
    @DarrenCook You might be right but I find a lot of people can be intimidated by those files. I know I was.
  • Casey Watson
    Casey Watson about 10 years
    chooseCRANmirror(ind=81) is what Jared probably meant. It will bypass the prompt.
  • Jere Käpyaho
    Jere Käpyaho about 10 years
    This should be the accepted answer. The Apple support article about X11 support in OS X is at support.apple.com/kb/HT5293?viewlocale=en_US&locale=en_US
  • Ben Mosher
    Ben Mosher about 10 years
    The problem is likely that the window doesn't show because of X11, but arguably, chooseCRANmirror()/repos parameter are much simpler solutions.
  • Andy Barbour
    Andy Barbour almost 8 years
    Can set options(menu.graphics = FALSE) in .Rprofile too
  • MichaelChirico
    MichaelChirico over 7 years
    For me, the repos pop-up came, I clicked a mirror, and then nothing happened; meanwhile, this worked fine. Programmatic solution > interactive solution, as usual! Thanks!
  • hobs
    hobs about 7 years
    And here are some mirrors to chose from, to be kind to cran: cran.r-project.org/mirrors.html
  • Steven C. Howell
    Steven C. Howell almost 6 years
    I found this a useful workaround to install a recent package into MRO. I spent a day trying to get a recent build of a package installed but the checkpoint function did not work as described using Anaconda's distribution of R, v3.4.3, with the snapshot set to 2017-09-01.
  • Jesse Adelman
    Jesse Adelman over 5 years
    I think this should be the accepted answer. It Just Works(tm), in all cases, including on headless systems (servers, IoT, etc.). Thanks, Dirk.
  • Dirk Eddelbuettel
    Dirk Eddelbuettel over 5 years
    And with the hindsight of several years later we now a proper CDN that is guaranteed to be network-close to everybody, and we use https now so make this https://cloud.r-project.org as the URL.
  • Jesse Adelman
    Jesse Adelman over 5 years
    I hope you don't mind, Dirk, but I just edited your post to reflect your suggestion.
  • Dirk Eddelbuettel
    Dirk Eddelbuettel over 5 years
    If I had wanted that I could have done it four hours ago myself. I prefer to let the historical record speak. But because vandals will come, I put a postscriptum in.