How do I reinstall a base-R package (e.g., stats, graphics, utils, etc.)?

10,464

Solution 1

(Since SO is nagging me not to continue the comment thread, I will post an answer.)

I believe that this problem will apply to any base package (but not to those installed from repositories, and probably not to Recommended packages): I am deeply skeptical that stats is the only package. It should occur for any of the packages in this list:

rownames(subset(as.data.frame(installed.packages()),Priority=="base"))

I'm sure it's theoretically possible to re-install a base package from scratch, but it will be much easier to re-install R. At a guess, it would take me about 15 minutes to re-install R, and I would feel lucky if I figured out how to re-install a base package on its own in less than an hour.

I'm pretty sure that re-installing R will not affect previously-installed packages: see e.g. http://cran.r-project.org/bin/windows/base/rw-FAQ.html#How-do-I-UNinstall-R_003f; that link is about uninstalling rather than re-installing, but this seems relevant:

Uninstalling R only removes files from the initial installation, not (for example) packages you have installed or updated.

Other choices would be

  • create another identical installation of R (on another machine, or in a non-default location); locate the relevant directories in your new installation and copy them over to your existing installation.
  • restore the relevant directories from your backup.

PS: obviously if you are doing this on a client's machine it would be a good idea to test my advice first ...

Solution 2

What worked for me was to copy the entire package folder from another to my R.home() directory.

Share:
10,464
user2912902
Author by

user2912902

Updated on June 04, 2022

Comments

  • user2912902
    user2912902 almost 2 years

    I have been using the "stats" package in R 3.0.1 without any problems . But today i deleted the "stats" folder from the R library location and now I can't install it any more. I tried doing the same thing with other packages but I could install everything except "stats"

    install.packages("stats", dep = TRUE, repos="http://cran.cs.wwu.edu")
    
    ## Installing package into ‘%Default R Lib Installation Path%’   
    ## (as ‘lib’ is unspecified)  
    ## Warning in install.packages :   package ‘stats’ is not available (for R version 3.0.1)
    

    I also tried downloading it from other sources like "http://cran.ma.imperial.ac.uk/" but nothing works . Any ideas?

  • user2912902
    user2912902 over 10 years
    I verified and none of the base packages can be re installed. So i guess re installing R is the most easier and cleaner way of doing this.
  • Serenthia
    Serenthia over 8 years
    If on OSX: I recommend installing R using Homebrew right from the start. Then un/reinstalling it is as simple as brew uninstall r, brew install r. This got my base packages back in less than a minute!