Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in R: (Package which is only available in source form, and may need compilation of C/C++/Fortran)

I'm trying to install the 'yaml' and 'stringi' packages in R-Studio, and it keeps giving me these errors:

> install.packages("stringi")
Package which is only available in source form, and may need compilation of C/C++/Fortran: ‘stringi’
These will not be installed

or

> install.packages('yaml')
Package which is only available in source form, and may need compilation of C/C++/Fortran: ‘yaml’
These will not be installed

How can I get these to install properly?

like image 449
wanax Avatar asked Jul 06 '15 15:07

wanax


People also ask

What is a source package in R?

A source package is just a directory of files with a specific structure. It includes particular components, such as a DESCRIPTION file, an R/ directory containing . R files, and so on.

What is the correct way to install the packages in R?

Open R via your preferred method (icon on desktop, Start Menu, dock, etc.) Click “Packages” in the top menu then click “Install package(s)”. Choose a mirror that is closest to your geographical location. Now you get to choose which packages you want to install.

Why I Cannot install package in R?

Changing the configuration in R Studio to solve install packages issue. Go To Tools -> Global option -> Packages. Then uncheck the option “Use secure download method for HTTP”. For other RStudio issues refer to official Troubleshooting Guide here.

How do I enable a package in R?

packages(' ') command. Alternatively, you would go to the packages field in Rstudio, click install packages, choose the package and click install. If you have the package on your computer, it is not ready to use yet. You need to attach/load/activate (synonyms) the package.


3 Answers

The error is due to R being unable to find a binary version of the package on CRAN, instead only finding a source version of the package and your Windows installation being unable to compile it. Usually this doesn't occur, but in this case was caused by the (temporary) outage of some of the mirrors at CRAN. If you type:

> getOption('repos')                                 CRAN                            CRANextra             "http://cran.rstudio.com" "http://www.stats.ox.ac.uk/pub/RWin"  attr(,"RStudio") [1] TRUE 

You will see that R uses "http://cran.rstudio.com" by default to look for a package to download. If you see the cran mirrors web page you can see at the top that "http://cran.rstudio.com" actually redirects you to different servers world wide (I assume according to the geo location).

When I had the above issue, I solved it by manually changing the repo to one of the urls in the link provided. I suggest you use a different country (or even continent) in case you receive the above error.

I provide below some of the urls in case the link above changes:

  1. Brazil http://nbcgib.uesc.br/mirrors/cran/
  2. Italy http://cran.mirror.garr.it/mirrors/CRAN/
  3. Japan http://cran.ism.ac.jp/
  4. South Africa http://r.adu.org.za/
  5. USA https://cran.cnr.Berkeley.edu/

You need to run the function install.packages as follows:

install.packages('<package_name>', repo='http://nbcgib.uesc.br/mirrors/cran/') #or any other url from the list or link 

One of them should then work to install a binary from an alternative mirror.

like image 111
LyzandeR Avatar answered Sep 18 '22 23:09

LyzandeR


You need to install RTools to build packages like this (i.e., a source package rather than a binary). After you install Rtools, then try again to install.packages("ggplot2") and R will prompt you with:

Do you want to attempt to install these from source? y/n: 

(see the picture below)

You need to answer y and it will try to compile the package so it can be installed.

enter image description here

like image 29
Stas Prihod'co Avatar answered Sep 16 '22 23:09

Stas Prihod'co


Struggled with this issue today, solved it for now by first downloading the windows binary and then installing e.g.

install.packages("https://cran.r-project.org/bin/windows/contrib/3.3/stringi_1.1.1.zip", repos =NULL)

Just go to https://cran.r-project.org/ and then R Binaries/Windows/contrib and copy the url as argument to install.packages()

like image 22
Steven Wink Avatar answered Sep 20 '22 23:09

Steven Wink