Always reinstalling packages - r

I just need to solve a problem with my RStudio. I have the lastest version on both R & RStudio, but every time that I reboot the PC ad open the program it tells me that some packages are not installed. After several times I have noticed that the problematic packages are: stringi, MASS, survival or Rcpp.
Also if I have to install another package which depends on them a warning appears saying that the packages mentioned are not updated, and it gives me the option to update all.
I tried to reinstall them and enter as an admin in RStudio but nothing works so, does anyone know what is happening here? Thanks for your help.

R packages are installed into libraries. The location of libraries searched by R is determined by the value of .libPaths(). Likely you have the problematic packages installed in more than one library; check for the same package installed in both dir(.libPaths()[1]) and dir(.libPaths()[2]), for instance.
Use remove.packages() with the lib= argument to remove one installation.
My practice is to install R and base packages only in the default library (possibly as administrator), and to install all other packages in a library that I as a regular user have access to. The personal library is the first entry in .libPaths(), which is the default location for package installation. See ?.libPaths for how to set up libraries; all library paths have to exist, else R silently drops them from .libPaths(). I use a setting in ~/.Renviron. Thus
> .libPaths()
[1] "/home/mtmorgan/R/x86_64-pc-linux-gnu-library/3.5-Bioc-3.8" # personal
[2] "/home/mtmorgan/bin/R-3-5-branch/library" # base
> sapply(.libPaths(), function(path) length(dir(path)))
/home/mtmorgan/R/x86_64-pc-linux-gnu-library/3.5-Bioc-3.8
236
/home/mtmorgan/bin/R-3-5-branch/library
30

Related

installation of R creates two library paths

I have observed that R installation in Windows creates two library paths automatically.
.libPaths()
# [1] "C:/Users/User/Documents/R/win-library/3.4"
# [2] "C:/Program Files/R/R-3.4.0/library"
What is the use of these while installing new packages and which library is used? I have frequently observed the installed packages being missed and need to install again. How do you maintain these two paths and manage the libraries while using R or RStudio in Windows?
Installing into C:/Program Files/R/... makes a package available to all users of the computer.
It is the R default, but installing a package there from within R (using install.packages() requires that R is started with administrator privileges.
Installing into C:/Users/Username/... makes the package available to the present user only, but does not require administrative rights.
R tracks these paths automatically, and looks in both directories when it is asked to load a package with require() or library(). No user input should be required.
When you update R, the version number will of course change, meaning that R will no longer look in the folders whose paths contained the previous version number. Some R updaters (e.g. installR) offer to copy packages from the "old" paths to the "new" paths, though an manually re-installing packages means that you can be sure that you are using the latest version of each package, and that you don't waste disk space and update time on packages that you are no longer using.

In continuation to previously asked "Unable to work with R-extension in NetLogo"

After changing all the needed environment varaibles ( Control Panel/ System/Advanced system settings/Environment Variables) in windows 8, when I am installing rJava Package I get errors as below
I tried in MsDOS immediately after changing environment variables,
first step >R "it was successful"
second >install.packages("rJava") "got error in this step"
then I tried >install.packages("rJava", repos="https://cran.rstudio.com/") "but again I did not succeeded"
I am tired of trying all this, I referred many links already but all in vain. Yes, I am using Proxy also. Please help any one.
1) It seems a download problem first. So do this:
Download rJava_0.9-8.zip from CRAN (cran.r-project.org/web/packages/rJava/index.html). Then, in Revolution R Enterprise; Packages - "Install Packages From local Zip Files..." - Choose rJava_0.9-8.zip - OK. If the problem is solved then OK.
If the problem persists, try the following Step.
2) Look at DESCRIPTION file in rJava (in library location):
Package: rJava
Version: 0.9-8
....
Depends: R (>= 2.5.0), methods
....
NeedsCompilation: yes
Your R version may be incompatible. Look at the warning: "rJava is not available for R3.3.0" in your screenshot. So do this:
Unzip file rJava_0.9-8.zip to R's working directory; the folder rJava is created there. Change R version accordingly (you may introduce lower version number in Depends section). Save the changed DESCRIPTION file. Apply classical procedure:
library(roxygen2) # install this package first if not done yet
library(devtools) # install this package first if not done yet
library(digest) # install this package first if not done yet
Note: Since rJava folder is created manually, no package.skeleton is needed at this stage.
roxygenize("rJava")
build("rJava")
install("rJava")
The above technique must solve the problem (It solved previously many R version problems!).
Analyze this one also:
Install a specific release of bioconductor package (where the solution I wrote solved the problem of the questioner).
If you still have problems, trigger the following:
sessionInfo(); getwd(); .libPaths()
and print the output in your question so that we can analyze if you have any machine-spesific or installation-spesific problems.

Error: "Package not available" for a package that should be current [duplicate]

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?
(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 ...
What worked for me was to copy the entire package folder from another to my R.home() directory.

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?
(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 ...
What worked for me was to copy the entire package folder from another to my R.home() directory.

Error in loadNamespace(name) : there is no package called 'Rcpp'

I am trying to embed RInside to my application on win7 64-bit system but when I initialize an RInside:
Rin = new RInside(argc, argv);
the following message appears:
Error in loadNamespace(name) : there is no package called 'Rcpp'
This error only occurs with Windows.
I think you get that issue when your .libPaths() differ--in other words run the .libPaths() function to see the paths stored by R for its use. Then check where RInside is installed, and make sure Rcpp is installed there too. It is a setup issue.
In other words, it should work if you have Rcpp and RInside installed where the basic R libraries are. Otherwise you have to tell the (embedded) R session about the other location (and before it starts).
There are more Windows users on the list, so you could try asking on rcpp-devel.
First get your default library locations by command ".Library" in R.
Get Rcpp package from https://cran.r-project.org/web/packages/Rcpp/index.html.
Unzip and copy folder "Rcpp" to your default library locations obtained from step1.
Now you are ready to install packages which have dependencies on Rcpp.
Dirk is right in this case, BUT if the .libPaths() does not work, then please also check if you have the latest packages.
I am posting this as an ancillary answer backup which I ran into with the shiny package backend switch of their code needing Rcpp!
In this case of getting the "no package" error message, I fixed it by:
Selecting devtools package and then using this line below. (if you don't have devtools then get it with install.packages("devtools")
devtools::install_github("rstudio/shiny")
The development version of the package handled this better, and added the package as a dependency.
Mods - I realize this is an answer to an old question, but I might help others not wasting an hour like I just did.
You might find it easy if the answers are for both R studio users and non R studio users.
R Studio users
First get your default library locations by command ".Library" in R.
Get Rcpp package from https://cran.r-project.org/web/packages/Rcpp/index.html.
Unzip and copy folder "Rcpp" to your default library locations obtained from step 1, you will find another folder named library, paste the unzip folder in it.
Non R studio Users
First get your default library locations by command ".libPath" in R.
Get Rcpp package from https://cran.r-project.org/web/packages/Rcpp/index.html.
Unzip and copy folder "Rcpp" to your default library locations obtained from step 1, you will find another folder named library, paste the unzip folder in it.
I was also getting this error while trying to run the 'ggplot' function from the ggplot2 package. After trying the suggestions posted here and elsewhere (checking file paths, restarting R, clearing out my environment, etc.) and encountering several other cryptic error messages, it turned out that I needed to download the latest version of base R for Windows (v3.4.1) and update my version of R-Studio to the latest version also (v1.0.153).
After doing this my 'ggplot' function was working again and I was able to render my figure from R Studio without any further issues.
I was also getting this message when trying to use ggplot. I first updating both my R for Windows to 3.4.3. Then updating R studio to version 1.1.423; then, updating all of the packages and being sure to access the R version 3.4.3 from R studio, I still got the message. None of these things fixed the error. I was ready to give up until I noticed that I was calling library(ggplot) and had ggplot::ggplot in my code. THIS WAS THE PROBLEM. I changed it to library(ggplot2) and the instance to ggplot2::ggplot(...). THIS FIXEd the problems.
I was facing a similar issue, and I simply installed the said package. It's working perfectly for me.

Resources