Unable to install specific packages in GoogleColab with R - r

I'm trying to prepare a report to my colleagues and students. I think the best way to make it reproducible is through Google Colab. My analysis was performed using R and some packages available on CRAN.
I am using a Jupyter Notebook with R kernel. I used the followinf link to create a Notebook with netive R kernel: https://colab.research.google.com/notebook#create=true&language=r. As you can see as follows, its running R.
a <- 1
print(a)
However, when I try to install the exactextractr package I get the following error:
install.packages("exactextractr")
Output:
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
also installing the dependencies ‘proxy’, ‘e1071’, ‘wk’, ‘sp’, ‘terra’, ‘classInt’, ‘s2’, ‘units’, ‘Rcpp’, ‘raster’, ‘sf’
Warning message in install.packages("exactextractr"):
“installation of package ‘units’ had non-zero exit status”
Warning message in install.packages("exactextractr"):
“installation of package ‘sf’ had non-zero exit status”
Warning message in install.packages("exactextractr"):
“installation of package ‘exactextractr’ had non-zero exit status”
The package was not installed:
library(exactextractr)
Output:
Error in library(exactextractr): there is no package called ‘exactextractr’
Traceback:
1. library(exactextractr)
What is the problem here?

Because the Linux variant underlying the GoogleColab is Ubuntu, you could also take advantage of r2u which brings about 20,000 binary CRAN packages with full dependencies to Ubuntu. So if (here) libudunits is needed, it gets installed!
A have a quick demo gif in this tweet (as SO limits image sizes) -- 17s total for everything from a 'blank' start in a container with just R, and r2u set up. This works in any Ubuntu system on stanard x86_64 (ie Intel or AMD): laptop, desktop, server, cloud, continuous integration, ... Give it a try -- as the demo shows it installs correctly via a single install.packages("exactextractor") from R!

Some of the packages that you are trying to install (exactextractr, terra, sf, units) have system dependencies. You can see that on the CRAN pages for these packages (here for terra) under "SystemRequirements".
In this case, you need to have GDAL, GEOS, PROJ, and udunits-2. Depending on the underlying linux system you can do something like the below to install them.
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
sudo apt-get install libudunits2-dev libgdal-dev libgeos-dev libproj-dev
This is essentially what r2evans suggests in the comments. And there is no doubt in my mind that what he says is correct.
See the github pages for more guidance on installing these packages. Here for "terra".
Also, try to install the dependencies one by one, so that it becomes clearer where the problem is.
E.g.
install.packages(‘proxy’)
install.packages(‘e1071’)
install.packages(‘wk’)
install.packages(‘sp’)
install.packages(‘terra’)
Etcetera.

Do this in one cell - R Colab doesn't support sudo directly.
system('sudo apt install libudunits2-dev')
Then this should work (I tried it successfully)
install.packages("exactextractr")

Related

R package 'gfortran' is not available (for R version 3.3.1)

I'm trying to install the package 'gfortran' (because the package 'deSolve' demands it to be insatlled) but get the error:
install.packages("gfortran")
Warning in install.packages :
package 'gfortran' is not available (for R version 3.3.1)
How can I solve it?
You should install gfortran on your device, not in the R console.
The steps you should take are nicely written here.
In short,
Remove existing gfortran installations
Install Xcode from the App Store
Run in your terminal:
xcode-select --install
Install gfortran. You can find all releases here
Go back to R and install your desired package

R 'mvpart' package - any option to use in R 3.1.x?

I would like to use functions in the mvpart package in R. I know it has been removed from CRAN, but I tried installing archive versions available here: http://cran.r-project.org/web/packages/mvpart/index.html
install.packages("D:/mvpart_1.6-2.tar.gz", repos = NULL, type = "source")
I get this result:
Installing package into ‘C:/Users/jk/Documents/R/win-library/3.1’
(as ‘lib’ is unspecified)
* installing source package 'mvpart' ...
** package 'mvpart' successfully unpacked and MD5 sums checked
** libs
*** arch - i386
Warning: running command 'make -f "C:/PROGRA~1/R/R-31~1.3/etc/i386/Makeconf" -f "C:/PROGRA~1/R/R-31~1.3/share/make/winshlib.mk" SHLIB="mvpart.dll" OBJECTS="anova.o branch.o bsplit.o choose_surg.o dist.o fix_cp.o formatg.o free_tree.o gini.o graycode.o insert_split.o make_cp_list.o make_cp_table.o mrt.o mysort.o nodesplit.o partition.o poisson.o pred_rpart.o rpart.o rpart_callback.o rpartexp2.o rpcountup.o rpmatrix.o rundown.o rundown2.o s_to_rp.o s_xpred.o surrogate.o usersplit.o vgdist.o xdiss.o xval.o"' had status 127
ERROR: compilation failed for package 'mvpart'
* removing 'C:/Users/jk/Documents/R/win-library/3.1/mvpart'
Warning in install.packages :
running command '"C:/PROGRA~1/R/R-31~1.3/bin/x64/R" CMD INSTALL -l "C:\Users\jk\Documents\R\win-library\3.1" "D:/mvpart_1.6-2.tar.gz"' had status 1
Warning in install.packages :
installation of package ‘D:/mvpart_1.6-2.tar.gz’ had non-zero exit status
My questions are: Did I do something wrong here - is there a way to install 'mvpart'? Or, is there another package that will do multivariate partitioning, similar to 'mvpart'?
Option 1:
An archive install must be compiled, as it's stored as source code. Probably, you have not installed the R Tools compiler for Windows. Follow the install instructions here.
Once that was done, for me, mvpart installed flawlessly from the downloaded archive:
install.packages("C:/mydownload/path/mvpart_1.6-2.tar.gz", repos = NULL, type = "source")
Option 2:
If Option 1 doesn't get the job done, get the devtools package:
install.packages("devtools")
Use it to get the github version:
devtools::install_github("cran/mvpart")
I believe you'll still need the R tools compiler though
downloading Xcode from either the Apple AppStore or Apple Developer website solved my issues installing mvpart. The app version required iOS 10.13 as of this post, but it was easy to find a compatible older version on the website to download. After you download it, move it to your Applications folder and then open it. After that then the devtools:::install_github() worked for me.

"installation of package 'FILE_PATH' had non-zero exit status" in R

By installing the package in R using the following command:
install.packages('FILE_PATH', repos=NULL, type = "source")
I got the following error:
Installing package into ‘/home/p/R/x86_64-pc-linux-gnu-library/3.0’
(as ‘lib’ is unspecified)
Errore in rawToChar(block[seq_len(ns)]) :
embedded nul in string: 'PK\003\004\024\0\002\0\b\0]\xadVCr\xcb\xea\xfcR\0\0\0\xa7\0\0\0\027\0\0\0bivpois-Rcode/.Rhistory+\xce/-JN\xd5PO\xca,+\xc8\xcf,\xd6+IL\xcaI\xd5\vR\xd7\xe4\xe5*\x86J\xe5\xe4\xea%\025`\b\xa5d\xa2\v楖\xe7%\xe6'
Warning message:
In install.packages("/home/p/Research/14_bivpois-Rcode.zip", repos = NULL, :
installation of package ‘/home/p/Research/14_bivpois-Rcode.zip’ had non-zero exit status
The R version is the 3.0.2 (2013-09-25) -- "Frisbee Sailing" and the OS is Linux Mint (UNIX).
Why Do I get that error and what does it mean:
installation of package ‘/home/p/Research/14_bivpois-Rcode.zip’ had non-zero exit status
in R?
You can find the package here and the file 14_bivpois-Rcode.zip is the source.
I tried to install that locally and the path is the correct one.
Any suggestion to install that package in UNIX?
Simple install following libs on your linux.
curl: sudo apt-get install curl
libssl-dev: sudo apt-get install libssl-dev
libcurl: sudo apt-get install libcurl4-openssl-dev
xml2: sudo apt-get install libxml2-dev
The .zip file provided by the authors is not a valid R package, and they do state that the source is for "direct use" in R (by which I assume they mean it's necessary to load the included functions manually). The non-zero exit status simply indicates that there was an error during the installation of the "package".
You can extract the archive manually and then load the functions therein with, e.g., source('bivpois.table.R'), or you can download the .RData file they provide and load that into the workspace with load('.RData'). This does not install the functions as part of a package; rather, it loads the functions into your global environment, making them temporarily available.
You can download, extract, and load the .RData from R as follows:
download.file('http://stat-athens.aueb.gr/~jbn/papers/files/14/14_bivpois_RDATA.zip',
f <- tempfile())
unzip(f, exdir=tempdir())
load(file.path(tempdir(), '.RData'))
If you want the .RData file to be available in the current working directory, to be loaded in the future, you could use the following instead:
download.file('http://stat-athens.aueb.gr/~jbn/papers/files/14/14_bivpois_RDATA.zip',
f <- tempfile())
unzip(f, exdir=tempdir())
file.copy(file.path(tempdir(), '.RData'), 'bivpois.RData')
# the above copies the .RData file to a file called bivpois.RData in your current
# working directory.
load('bivpois.RData')
In future R sessions, you can just call load('bivpois.RData').
You can try using command : install.packages('*package_name', dependencies = TRUE)
For example is you have to install 'caret' package in your R machine in linux : install.packages('caret', dependencies = TRUE)
Doing so, all the dependencies for the package will also be downloaded.
For those of you who are using MacOS and like me perhaps have been circling the internet as to why some R packages do not install here is a possible help.
If you get a non-zero exit status first check to ensure all dependencies are installed as well. Read through the messaging. If that is checked off, then look for indications such as gfortran: No such a file or directory. That might be due to Apple OS compiler issues that some packages will not install unless you use their binary version. Look for binary zip file in the package cran.r-project.org page, download it and use the following command to get the package installed:
install.packages("/PATH/zip file ", repos = NULL, type="source")
Did you check the gsl package in your system. Try with this:
ldconfig-p | grep gsl
If gsl is installed, it will display the configuration path. If it is not in the standard path /usr/lib/ then you need to do the following in bash:
export PATH=$PATH:/your/path/to/gsl-config
If gsl is not installed, simply do
sudo apt-get install libgsl0ldbl
sudo apt-get install gsl-bin libgsl0-dev
I had a problem with the mvabund package and this fixed the error
Cheers!
I was having a similar problem trying to install a package called AED. I tried using the install.packages() command:
install.packages('FILE_PATH', repos=NULL, type = "source")
but kept getting the following warning message:
Warning message:
In install.packages("/Users/blahblah/R-2.14.0/AED", :
installation of package ‘/Users/blahblah/R-2.14.0/AED’ had
non-zero exit status
It turned out the folder 'AED' had another folder inside of it that hadn't been uncompressed. I just uncompressed it and tried installing the package again and it worked.
Try use this:
apt-get install r-base-dev
It will be help. After then I could makeinstall.packages('//package_name')
I have had the same problem with a specific package in R and the solution was I should install in the ubuntu terminal libcurl.
Look at the information that appears above explaining to us that curl package has error installation.
I knew this about the message:
Configuration failed because libcurl was not found. Try installing:
* deb: libcurl4-openssl-dev (Debian, Ubuntu, etc)
* rpm: libcurl-devel (Fedora, CentOS, RHEL)
* csw: libcurl_dev (Solaris)
If libcurl is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libcurl.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
To install it I used the net command:
sudo apt-get install libcurl4-openssl-dev
Sometimes we can not install a specific package in R because we have problems with packages that must be installed previously as curl package. To know if we should install it we should check the warning errors such as: installation of package ‘curl’ had non-zero exit status.
I hope I have been helpful
I had the same problem, but the answer from #little_chemist helped me sorting it out. When installing packages from a file in a unix OS (Ubuntu 18.04 for me), the file can not be zipped. You are using:
install.packages("/home/p/Research/14_bivpois-Rcode.zip", repos = NULL, type="source")
I noticed the solution was as simple as unzipping the package. Additionally, unzip all (installation related?) packages inside, as #little_chemist points out. Then use install.packages:
install.packages("/home/p/Research/14_bivpois-Rcode", repos = NULL, type="source")
Hope it helps!

R: Having trouble installing rpanel

I am trying to install the packages rpanel and tkrplot on RStudio. After downloading and installing there I got this message:
downloaded 686 Kb
* installing *source* package ‘rpanel’ ...
** package ‘rpanel’ successfully unpacked and MD5 sums checked
** R
** data
*** moving datasets to lazyload DB
** demo
** inst
** preparing package for lazy loading
Error in structure(.External(.C_dotTcl, ...), class = "tclObj") :
[tcl] can't find package BWidget.
Error : unable to load R code in package ‘rpanel’
ERROR: lazy loading failed for package ‘rpanel’
* removing ‘..../R/i686-pc-linux-gnu-library/3.0/rpanel’
Warning in install.packages :
installation of package ‘rpanel’ had non-zero exit status
The downloaded source packages are in
‘/tmp/Rtmp1MdC0f/downloaded_packages’
I already installed BWidget on my own, but it didn't help.
Anyone any ideas about this problem and maybe can help me?
The system is Ubuntu 12.04.
Under windows 7 there is no problem and everything is working fine.
There are easier ways to install BWidgets. On my mac with Macports I did:
sudo port install BWidget
On Ubuntu you can probably install it with apt-get:
sudo apt-get install bwidget
"Stumbled across this while looking for an answer to the same question. Like an unfortunate number of library authors, the BWidgets people have assumed that the only people who need to use their libraries are planning to code with them. For those of us who've never used TCL, the installation instructions mean nothing.
From the a document called tuto-install-tkabber on the tkabber.jabber.ru website (irritating spam catcher won't let me post a URL), the answer is:
Install the BWidgets directory into the "lib" directory returned by:
whereis tcl
It should look something like: /usr/lib/tcl8.4"
from http://www.linuxquestions.org/questions/linux-software-2/where-to-install-bwidget-tcl-98583/ did the trick for me
Also I got BWidget from: http://sourceforge.net/projects/tcllib/files/BWidget/1.7.0/BWidget-1.7.0.zip/download
#Calimo's answer worked for me on Linux Mint 18.3 RStudio R 3.6.0. I would have commented in #Calimo's thread except for the stupid 50 reputation limit.
sudo apt-get install bwidget
Also works for Ubuntu 18 R 3.4.4 but if you get an X11 issue with rgl then this helped from #Ouistiti.
I had similar issues trying to get biotools working in Rstudio (on Ubuntu 16.04), where rpanel and tkrplot are required. Even after installing Bwidget per Calimo's answer, I got the error installation of package ‘tkrplot’ had non-zero exit status because tk.h: No such file or directory. If you look in the directory, this error is definitely correct. You need to get tk.h in there. I found out how to do so elsewhere on stackexchange:
Install tcl-dev package using apt or synaptic; tcl contains the
runtime, while tcl-devel contains header and development files. Do the
same with tk-dev
from:
https://stackoverflow.com/a/9649478/10405322
Thus,
sudo apt-get install tcl-dev
sudo apt-get install tk-dev
download BWidget from
http://sourceforge.net/project/showfiles.php?group_id=12883
once you get the archive BWidget-1.7.0.tar.gz move it to /usr/local/lib and install it with following code in terminal:
sudo mv /some_download_path/BWidget-1.7.0.tar.gz /usr/local/lib
cd /usr/loca/lib
sudo tar zxf BWidget-1.7.0.tar.gz
ok, done.

GenomicFeatures Package Installation Trouble

Sorry to be back so soon with a simple installation question, but my inability to solve it myself is seriously impairing my productivity. Anyway, I tried installing GenomicFeatures as suggested by the BC website.
> source("http://bioconductor.org/biocLite.R")
> biocLite("GenomicFeatures")
I received the following error messages (in addition to several warning messages)
ERROR: configuration failed for package ‘RCurl’
* removing ‘/home/tim/R/i686-pc-linux-gnu-library/2.15/RCurl’
ERROR: dependencies ‘XML’, ‘RCurl’ are not available for package ‘rtracklayer’
* removing ‘/home/tim/R/i686-pc-linux-gnu-library/2.15/rtracklayer’
ERROR: dependencies ‘XML’, ‘RCurl’ are not available for package ‘biomaRt’
* removing ‘/home/tim/R/i686-pc-linux-gnu-library/2.15/biomaRt’
ERROR: dependencies ‘rtracklayer’, ‘biomaRt’, ‘RCurl’ are not available for package ‘GenomicFeatures’
* removing ‘/home/tim/R/i686-pc-linux-gnu-library/2.15/GenomicFeatures’
So some problem with the dependencies I guess, but it seems strange that they would be automatically installed prior to GF. I am using version 2.15.0. Any clue as to what the problem might be? I'd be happy to provide more info as needed. Thanks.
Martin Morgan has a solution that I believe works in the comments. I'll elaborate on that a little bit.
The error messages are telling you that you need the RCurl and XML packages installed. Both of these packages require that your system has certain development packages on them. You appear to be running Linux. If you're using a Debian based system (Debian, Ubuntu, Mint, ...) then for RCurl to install you need to install libcurl4-openssl-dev and for XML to install you need to install libxml2-dev. You can accomplish this by relatively easily on the command line by typing
sudo apt-get install libcurl4-openssl-dev libxml2-dev
That should install the required packages and any dependencies. Then you should be able to install the RCurl and XML packages from within R.
install.packages("RCurl")
install.packages("XML")
At this point you have the required dependencies and should be able to install GenomicFeatures from Bioconductor.
source("http://bioconductor.org/biocLite.R")
biocLite("GenomicFeatures")
Just a note for those using Windows - getting RCurl and XML isn't necessarily easy, however, Dr. Brian Ripley provides binaries for these packages at his website and you can download them from there quite easily. Initially when I saw there was issues with RCurl and XML I thought it must be a windows user until I looked at the actual errors and realized it was a Linux user.

Resources