RStudio does not see packages after update to R 3.4 [duplicate] - r

This question already has answers here:
Change R default library path using .libPaths in Rprofile.site fails to work
(16 answers)
Closed 5 years ago.
I have Ubuntu 16.04 and after update of R to 3.4.1 version it does not see my packages even though they have also been updated:
> library(dplyr)
Error in library(dplyr) : there is no package called ‘dplyr’
Packages are there:
$ ls ~/R/x86_64-pc-linux-gnu-library/3.4/ | grep plyr
dplyr
plyr
My .libPaths:
> .libPaths()
[1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library" "/usr/lib/R/library"
Setting .libPaths to desired path does the thing just for one session. I'd like it to be permanent.
I also tried to set the variables R_LIBS, R_LIBS_SITE and R_LIBS_USER to desired path as indicated here but it worked only in the console (didn't work in RStudio).

Found the solution:
In the file /usr/lib/R/etc/Renviron there is a configuration of R.
In lines 43-45 there is:
# edd Jun 2017 Comment-out R_LIBS_USER
#R_LIBS_USER=${R_LIBS_USER-'~/R/x86_64-pc-linux-gnu-library/3.4'}
##R_LIBS_USER=${R_LIBS_USER-'~/Library/R/3.4/library'}
I have uncommented R_LIBS_USER=${R_LIBS_USER-'~/R/x86_64-pc-linux-gnu-library/3.4'}, restarted RStudio and now it works.
EDIT: Looking at the comments, it seems like a planned behaviour. Here is another solution.

I had a similar problem with Ubuntu 16.04. Call terminal R and try to install one any package in the terminal. Then use rstudio.

I had the same problem on Windows, maybe my solution works for you aswell. The default for R-Studio seems to be, that it looks for the packages in a folder that has the same name as the most recent R version you have installed.
So check in the Library Settings for R-Studio, (e. g. Tools -> Install packages -> Path beneath the search bar) it should say some path ending in ~/3.4.1 [Default], whereas the packages currently lie in ~/3.4.
What I did:
Copy/move the content from ~/3.4 to ~/3.4.1.
This is obviously not the nicest way, since that means moving the packages with every R update, but it worked for me.
Edit: formatting.

Related

R packages with Anaconda

I have Anaconda and I am learning to use it. I also installed R with it. It creates a separate enviroment " rstudio" with the default packages, but a lot of them appear with r-<name of the original package>, for example readxl is shown in the Anaconda enviroment as r-readxl. When I try to run in Rstudio, regardless of whether I type the original name of the package or the full "r-readxl" it does not find it. It says: there is no package called ‘r-readxl’.
Is there a way to tell Rsutdio that the packages in the Anaconda file are the ones of reference? How can I fix this?

Running an old version of R in Rstudio

I'm using a package (ggmap) that doesn't work on R 3.6.1 (Windows), so I would like to install a previous version of R. Once the version is installed, I found how to force Rstudio to use it (through the options panel).
The issue is I am not able to install a previous version. I've downloaded the directory (didn't do anything with it besides drag-and-drop into my R directory), but when I try to force Rstudio to use it, I get the following message:
"This directory does not seem to contain a valid R installation".
The parent directoy is the same that has the R 3.6.1, which works fine.
Thanks for any help!
I am using R version 3.6.0 (2019-04-26) and I was able to install the mentioned package:
install.packages('ggmap')
In my experience, sometimes I also think it's due to a version incompatibility when it isn't. For example, I might get a message similar to this:
Warning in install.packages :
package 'biomaRt' is not available (for R version 3.6.0)
To which most of the time the solution includes using setRepositories():
setRepositories()
Enter one or more numbers separated by spaces, or an empty line to cancel
1: 1 2 3 4 5 6 7 8
In this case, I added all of them just in case, which reassures that if the package exists and is available for my version, it will be installed (You may want to reset it again to a single repository, as it may slow the installation of other packages).
Edit: If you actually get the Error message I mentioned, you might be interested in looking at this answer if setRepositories() does not fix your issue.

Always reinstalling packages

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

Local libraries path removed from R path after minor upgrade [duplicate]

This question already has answers here:
R 3.4.1 "Single Candle" Personal Library Path Error: unable to create ‘NA’
(6 answers)
Closed 5 years ago.
I have a lot of packages installed in ~/R/x86_64-pc-linux-gnu-library/3.4/. Today, I opened R, and attempted to run some code, and I found that packages were not being recognised:
Error in library("some_package"): there is no package called ‘some_package’
I looked at the paths, and I got this:
.libPaths()
[1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library" "/usr/lib/R/library"
which explains why packages are not longer recognised. Now, I know how to solve this (add local path to R paths, e.g. modifying /etc/R/Renviron).
Notice that I updated R via sudo apt-get update.... However, the update was minor (from 3.4 to 3.4.1) (so this is not a duplicate of this question). Here is the command line output of the update/upgrade. It seems the issue might have been related to the update of /etc/R/Renviron, as the line Replacing config file /etc/R/Renviron with new version indicates.
My packages source is
deb https://cloud.r-project.org/bin/linux/ubuntu xenial/
My question is, why did this change happen? Does every minor change in R restores the paths to default? Is it somewhere explained in some documentation? I can't find a warning about it here or elsewhere.
It's related to 3.4.1's new(?) default behaviour of making the same library of R packages available to all users on your Linux system. See here for a neat solution: https://stackoverflow.com/a/44903158/4115816
(The thread also describes some other options.)

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.

Resources