Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 723
user2912902 Avatar asked Nov 25 '13 23:11

user2912902


People also ask

Do I have to reinstall R packages?

Once the package is installed, you keep that in your R library associated with your current major version of R. You will need to update & reinstall packages each time you update a major version of R.

How do I manually download R packages?

The most common way is to use the CRAN repository, then you just need the name of the package and use the command install. packages("package") .

Do I need to uninstall R before updating?

If you have older versions of either R , or Python , it is recommended to update them to the newest versions in order to avoid any errors. To do this, we firstly need to completely remove the currently installed versions.


2 Answers

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

like image 108
Luciano Silva Avatar answered Nov 02 '22 06:11

Luciano Silva


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

like image 24
Ben Bolker Avatar answered Nov 02 '22 04:11

Ben Bolker