Cannot install R packages in Jupyter Notebook - r

I am trying to run R code in Jupyter and the R Kernel was added. Most of the time, packages can be installed successfully. However, some of the packages, such as RCurl and ggmap, would got error while installing.
Example:
install.packages("RCurl")
Warning message in install.packages("RCurl"):
“installation of package ‘RCurl’ had non-zero exit status”Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
What should I do?

Try to specify CRAN as repository in your install.packages statement when installing RCurl and ggmap. For example:
install.packages("RCurl", repos='http://cran.us.r-project.org')
This Stack Overflow post on installing R packages through Anaconda/Jupyter beyond those included in R essential provides more detail.
(Side note: I had encountered the same issue when trying to install R packages on computer clusters. This solution worked for me.)

use conda comment:
conda install r-RCurl

I kept getting the non-zero exit status when trying to install packages with Jupyter notebook with R kernel and was failing because of multiple dependencies when wanting to install a package. I am not an expert in any of these so please forgive me if I make an error in explaining or if it is a non-issue for you but please feel free to comment to clear things out. I just want to share my success story so hopefully it can help someone else: I am working on a MacBook Pro. Here are the information I get when I run R.version() on my jupyter notebook with R kernel:
$platform 'x86_64-conda_cos6-linux-gnu'
$arch 'x86_64'
$os 'linux-gnu'
$system 'x86_64, linux-gnu'
$language 'R'
$version.string 'R version 3.6.1 (2019-07-05)'
These are the steps to take to fix the issue:
Go to https://anaconda.org/
Search the package name that you are trying to install
Copy the one line that is given to install the package, it should be something like:
Conda install -c r r-caret #conda install -c r r-package_name
NOTE: sometimes during installing packages, you’re asked whether or not you want to continue, so add --y at the end of the above statement to continue, so something like this
Conda install -c r r-caret --y
(I will always add it just to be on the safe side)
Click on the new launcher (+ icon) to create a new notebook with PySpark (once opened it has .ipynp extension)
On the first cell paste the copied line from step 2 and run
Once done, restart the kernel on the current notebook
Restart the kernel on your other notebook with R kernel
Run library(package_name) on your notebook with R kernel (e.x. library(caret))

install.packages("Hmisc", .libPaths(), repos='http://cran.us.r-project.org')
This command will install the packagae in the conda
"/home/user/anaconda3/lib/R/library" and use the cran r repository as source.
Add path in Anaconda
As per this answer,
one can also add additional paths in anaconda to load libraries from (for eg., the location where R studio saves the user-installed packages) with
.libPaths( c( .libPaths(), "~/userLibrary") )
For example, the following worked for me:
In Anaconda :
.libPaths( c( .libPaths(), "C:\Users\name\Documents\R\win-library\3.5") )
When I tried to add anaconda's library path to RStudio, it resulted in errors (The procedure entry point MARK_NOT_MUTABLE could not be located in the dynamic link library << arose 4 times in succession) after installation of a package, though the package seemed to load.
Replace name with your local user folder name
Add/change path in RStudio
A useful link to make changes in default user-installed library paths :
https://www.accelebrate.com/library/how-to-articles/r-rstudio-library
To find out where a package has been installed:
find.package('package_name')

The directions nobody else supplied worked for me, but I found this guide, and it worked. Spent way too much time trying all these when I just needed a few simple commands. https://developers.refinitiv.com/en/article-catalog/article/setup-jupyter-notebook-r
I already had R and python installed, so I skipped to step 3. The only seems to mention windows, but it worked for me on mac as well. After following them I was able to install the packages using install.packages("dplyr", repos = "http://cran.us.r-project.org") in a cell in jupyter.

You have to create a directory in which your package will be and do for eg:
install.packages('ggplot2',loc='your directory')

First Step: You can install the IRkernel packages by running the following command in an R console:install.packages('IRkernel')
Second Step: You will have to make Jupyter see the newly installed R kernel by installing a kernel spec. To install system-wide, set user to False in the installspec command IRkernel::installspec(user = FALSE)
Setup Jupyter Notebook for R

Related

InstallationWarning: package 'XYZ' is in use and will not be installed: R

I am trying to install package SBCK from R build using Rscript build.R -c -v -i in windows command prompt following the steps given here. However, I ended up with package SBCK being not installed because of following error/warning InstallationWarning: package 'SBCK' is in use and will not be installed. I have no package with name SBCK installed on my system, so I do not understand why I am getting this warning message and thus not to be able to install the R package.
I know that similar question have been asked before here but solution there does not work in my case.
I am using R version 4.2.0 on Windows 10.
Once 'build.R' is run, "SBCK_0.5.0.tar.gz" is created in the 'SBCK-R' folder.
You can now install it via the package archive file option or pointing to that file in the install.packages command. I faced the same issue and this solved it.

Installing R 4.0.2 version

I used to work in R 3.4.0 version. Hovewer, this version doesn't support such packages as keras and tensorflow.
I was adviced to upgrade my R version to the newest one.
I downloaded the most recent R version 4.0.2 from the official site, then ran the following code:
install.packages("keras")
library(keras)
install_keras()
And got the following error:
Error in install_keras() :
You should call install_keras() only in a fresh R session that has not yet initialized Keras and TensorFlow (this is to avoid DLL in use errors during installation)
After this, when I tried to quit R session by q() , I faced the following error:
Error: option error has NULL value
Error: no more error handlers available (recursive errors?); invoking 'abort' restart
Error: option error has NULL value
I've never faced such an error before. When I used old R version, I typed q() and then had to choose between y and n. No errors appeared.
I'm asking you to help to to solve this problem.
You need to create a new environment and then you can install R 4.+ in Anaconda. Follow these steps.
conda create --name r4-base
After activating r4-base run these commands
conda activate r4-base
conda install -c conda-forge r-base
conda install -c conda-forge/label/gcc7 r-base
Finally, you will notice r-basa version 4 will be installed.
Thereafter, you can install any supported packages. But with this only, you won't have the ability to use it in the Jupyter notebook. You need to install install.packages('IRkernel') and Jupyter notebook as well if you want to use it. Otherwise you are good to go with R-Studio.
For Jupyter Installation and RKernel.
conda install jupyter
Then open the R console. Write in R console
install.packages('IRkernel')
IRkernel::installspec()
Congrats! You can use Notebook for Python and R.
Find the location of R.exe on your computer. In my computer, this executable is at
C:\Program Files\R\R-3.4.3\bin
Open another Anaconda Prompt as Administrator and change directories to wherever R.exe is on your computer with cd file path. On my computer, it’s cd C:\Program Files\R\R-3.4.3\bin, but it might be different for you.
Then run R from within Anaconda Prompt in Admin mode with R.exe
You’ll notice that you’re in an R session. From here, run the following three commands into the terminal.
install.packages("devtools")
devtools::install_github("IRkernel/IRkernel")
IRkernel::installspec()
In order, they (1) install the devtools package which gets you the install_github() function, (2) install the IR Kernel from GitHub, and (3) tell Jupyter where to find the IR Kernel.
Open Jupyter notebook and enjoy your new R kernel!
Get more information here
#Rheatey Bash works perfectly. but i was facing python.exe this program cant start because api-ms-win-core-path-l1-1-0.dll python system error. this is a problem running on windows 7 but i resolved this issue by installing the kernel following https://richpauloo.github.io/2018-05-16-Installing-the-R-kernel-in-Jupyter-Lab/ and it works fine

Installing rsvg library in R 4.0.2 (conda-forge)

I'm facing difficulties downloading the r package rsvg. I created first an environment with conda for the latest R version 4.0.2 following these instructions. I was able to download many other R packages & bioconductor packages without problem, however, this one produces huge pile of lines while configuring it and ends with errors downloadind its dependencies (systemfonts, stringi, stringr, gdtools, magick, svglite, knitr). My exact command is install.packages("rsvg", dependencies =T). Trying to download each of those packages produced also a tree of required dependencies (with configuration fail at the end of each).
Among the lines I noticed this error /user/include/freetype2/freetype/config/ftheader.h:3:12: fatal error x86_64-linux-gnu/freetype2/config/fthreader.h no such file or directory which make me suspect that my R installation is incopmlete or corrupted. I tested it with other R versions (e.g. R 3.6.0) yet the same error appear. Installing it on windows (Rstudio 3.6.2) also didn't work, and now I'm wondering if this package needs to be installed differently or it is system related problem? Any help would be highly appreciated
You need to create a new environment and then you can install R 4.+ in Anaconda. Follow these steps.
conda create --name r4-base
After activating r4-base run these commands
conda install -c conda-forge r-base
conda install -c conda-forge/label/gcc7 r-base
Finally, you will notice r-basa version 4 will be installed.
Thereafter, you can install any supported packages. But with this only, you won't have the ability to use it in the Jupyter notebook. You need to install install.packages('IRkernel') and Jupyter notebook as well if you want to use it. Otherwise you are good to go with R-Studio.
For Jupyter Installation and RKernel.
conda install jupyter
Then open the R console. Write in R console
install.packages('IRkernel')
IRkernel::installspec()
Congrats! You can use Notebook for Python and R.

Installing R packages in macOS Mojave: Error in if (nzchar(SHLIB_LIBADD))

I have been trying to install R packages directly from the terminal but I am struggling much more than setting up the libraries I want in Windows. Sometimes it works if I install every single dependency for more complex packages by downloading them from CRAN and placing them in the R folder.
I appreciate this is not efficient but the recurrent error if I run R within the terminal while installing some of the packages is the following:
** libs
Error in if (nzchar(SHLIB_LIBADD)) SHLIB_LIBADD else character() :
argument is of length zero
* removing ‘/anaconda3/lib/R/library/<package name>’
[...]
In install.packages("<package name>") :
installation of package ‘fpc’ had non-zero exit status
I have been looking across many forums but the only solution I found so far is to install single dependencies manually by downloading them and dropping them in the master R folder. It is taking way longer than expected.
Any suggestion will be appreciated. Thanks
in my case (centos 7):
/home/xilab/miniconda3/lib/R/etc/Makeconf is a empty file!
find ~ -name Makeconf
/home/xilab/miniconda3/pkgs/r-base-3.6.1-hce969dd_0/lib/R/etc/Makeconf
/home/xilab/miniconda3/pkgs/r-base-3.6.1-h8900bf8_2/lib/R/etc/Makeconf
/home/xilab/miniconda3/envs/python2.7/lib/R/etc/Makeconf
/home/xilab/miniconda3/lib/R/etc/Makeconf
/home/xilab/miniconda3/pkgs/r-base-3.6.1-hce969dd_0/lib/R/etc/Makeconf is not empty,so:
mv /home/xilab/miniconda3/lib/R/etc/Makeconf /home/xilab/miniconda3/lib/R/etc/Makeconf.backup
cp /home/xilab/miniconda3/pkgs/r-base-3.6.1-hce969dd_0/lib/R/etc/Makeconf /home/xilab/miniconda3/lib/R/etc/Makeconf
problem solved!
I have seen this problem in conda version of R where /yours/anaconda/environment/lib/R/etc/ has a file Makeconf.mro.original together with an empty Makeconf file. This should not be intended.
During installation of some packages R checks what is within this Makeconf file, one such check is for SHLIB_LIBADD.
I just backed up the empty (or whatever) Makeconf file. Then copied Makeconf.mro.original to Makeconf.
This solved my case.
EDIT:
Recently I saw in centos-machine that Makeconf.mro.original file is not made after install.packages("name of library") failed. There is no easy solution for this.
In my case R installation was inside a conda environment. So, I created a new conda environment with R installation. The fresh installation has a Makeconf file in etc directory. So, I copied the Makeconf file from fresh R to my previously working R's etc directory.
It may be better to keep a backup copy of Makeconf from etc to a Makeconf.bak for future problems, in your working R etc directory.
I hope this helps for some cases.
I had this problem when trying to run install.packages("RPostgres") in a conda-installed version of R . The solution was to use conda as the package manager instead of R's install.packages function. That meant running these commands at a normal system command prompt (not in R):
conda search -c conda-forge RPostgres
# shows various versions of r-rpostgres
conda install -c conda-forge r-rpostgres

R Notebook Creation Failed

When I go File-New File-R Notebook, it tells me to install some packages, but then it fails giving me this message:
Notebook Creation Failed:
"One of more packages required for R Notebook creation were not installed"
I'm trying to install those packages manually, but the package installation window disappears so quickly that I can't even see which ones I should install.
I googled it around, but couldn't fine any resource.
Can anyone help me with this?
Maybe at least provide a list of packages required to run R Notebook?
R notebooks are actually not created with a package named either RNotebook or notebook or anything similar but rather with the rmarkdown package, and it needs to be a current version. So the command would be:
install.packages("rmarkdown", dependencies=TRUE) # needs to be >= version 1.3
Then your pulldown menu selections should succeed in a current version of RStudio. .... at least that is if you have the system requirements listed in the CRAN webpage:
SystemRequirements: pandoc (>= 1.12.3) - http://pandoc.org
This worked for me:
Install latest version of R from cran website
Start RStudio pointing to this version of R.
On Mac set env variable as show below and start RStudio from terminal
Then "Install Package" in RStudio for "markdown" and other ppackages will work properly installing latest required packages to open notebook
➜ export RSTUDIO_WHICH_R=/usr/local/bin/R
Don't press the error message, and read whatever you can from the installation popup under it. In my case the last message was that it has problems compiling "digest". I installed "digest" manually (install.packages("digest",type = "binary")). Then it all worked.
Mac, R version 3.6, Rstudio desktop 1.2.
I had exactly the same problem. By reading the error logs, I found g++ command not found. So just installed it and it worked fine next time I've tried.
I faced the same problem. I am using the latest version of R and RStudio and all of the installed packages are up-to-date.
Now, talking about the error in installation of packages. Follow the steps below and you will have R Notebook up and running:
Run the command
install.packages("rmarkdown", dependencies=TRUE)
You will observe several messages on the console during installation. Browse through them and jot the ones where there is ERROR in installation of some other dependent package. In my case, it was 'backports'. The error message will be like this:
ERROR: compilation failed for package 'backports'
It can be different in your case but the point is to note down the name of the package that is facing compilation issues. Use an editor(npp) to save the name of the package.
Once you get the name of the package, execute the following command:
install.packages("backports", type="binary")
After successful execution of the above command, go to File drop down and select R Markdown. Go with auto installation of the rmarkdown and rprojroot packages. They will be successfully installed and you can now use R Notebook
Let us know if this solution worked for you.
I just found the answer myself so I'm posting.
I guess there was something wrong with the server.
I went into tools-global options-packages and chose different CRAN mirror, then it worked.
UPDATE YOUR VERSION OF R - that was my solution, I had the same problem.
( First two commands ensure you get the MOST RECENT version of R which I found on a Digital Ocean page)
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
$ sudo add-apt-repository 'deb [arch=amd64,i386] https://cran.rstudio.com/bin/linux/ubuntu xenial/'
$ sudo apt-get update
$ sudo apt-get install r-base
WITHOUT the first two lines I ended up with R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree"
WITH the first two lines I got R version 3.4.4 (2018-03-15) -- "Someone to Lean On"
After reinstalling R Studio, the Files -> RMarkdown was able to install all those subpackages and WORK. Hurray!

Resources