30

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?

Giulio Vian
  • 8,248
  • 2
  • 33
  • 41
wanax
  • 301
  • 1
  • 3
  • 4
  • 1
    What operating system are you on? It looks like you don't have compiler on your machine. – nrussell Jul 06 '15 at 15:43
  • 1
    Ouch! sorry, I'm on Windows 7, R-Studio version 0.99.451, R i386 v.3.2.1. How could I get/install/connect to R a compiler? – wanax Jul 06 '15 at 15:45
  • 3
    You need to instal [Rtools](http://cran.r-project.org/bin/windows/Rtools/) – hrbrmstr Jul 06 '15 at 15:46
  • 1
    Which CRAN mirror are you using? Binaries are currently available on CRAN. – Roland Jul 06 '15 at 15:48
  • I've installed RTools, I'm using "Global (CDN) - RStudio" as CRAN mirror, and now I've this error: `Warning in install.packages : package ‘stringi’ is not available (for R version 3.2.1)` – wanax Jul 06 '15 at 16:02
  • Update R to the most recent version. – gagolews Jun 01 '16 at 09:05
  • 3
    I am using R 3.5 version. I am getting the same error today. How do you resolve it? Anyone? @wanax – Naive_Natural2511 Apr 26 '18 at 10:09
  • 7
    @xkcvk2511 I'm getting the same error also today with 3.5 but only with `data.table`. Other packages installed fine - how is it for you? I already tried different mirrors and I have Rtools installed... – kath Apr 26 '18 at 12:49
  • @kath Unfortunately, I can't install Rtools in my laptop. I tried installing data.table 1.10.5 through zip file. I receive the following error. `Error: package or namespace load failed for ‘data.table’: package ‘data.table’ was installed by an R version with different internals; it needs to be reinstalled for use with this R version` – Naive_Natural2511 Apr 26 '18 at 13:16
  • @xkcvk2511 Maybe data.table is not available for R 3.5 yet? Do you have problems with different packages? – kath Apr 26 '18 at 15:50
  • 1
    @kath I followed the solution of Matt mentioned in comment thread. It works now. https://stackoverflow.com/questions/49838553/data-table-package-in-r-3-5-does-not-install May be you should give it a go! cheers. – Naive_Natural2511 Apr 26 '18 at 18:39
  • @xkcvk2511 Thanks, I didn't see that :) – kath Apr 27 '18 at 07:30

7 Answers7

27

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.

Thomas
  • 43,637
  • 12
  • 109
  • 140
LyzandeR
  • 37,047
  • 12
  • 77
  • 87
14

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

Thomas
  • 43,637
  • 12
  • 109
  • 140
Stas Prihod'co
  • 864
  • 9
  • 13
9

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()

Steven Wink
  • 127
  • 1
  • 6
  • Following your advice I realized that the package was not available as binary for my older R version. Once I upgraded it, the problem vanished. Thanks! – LuedDev Feb 26 '19 at 12:51
2

Install the package from a zip file - downloadable from the r-project website.

In basic R

  1. go to Packages
  2. Install packages from local files.

In RStudio

  1. go to Packages
  2. Install packages
  3. Install from Package Archive File.
loki
  • 9,816
  • 7
  • 56
  • 82
1

I had this issue when using an out-of-date version of R, so no binaries were available. The simple solution was to update my version of R.

qwr
  • 9,525
  • 5
  • 58
  • 102
1

Anything worked for me, until I found out my computer had an old version of R installed. Uninstalling everything and installing the newest R version worked!

0

I had to download the latest version of Rtools:

enter image description here

Go into the downloads folder and double click it to install it.

Close and reopen any R session.

Now packages should install like normal.

However, if you still have trouble, try installing the package from source (using type="source")

Like this:

install.packages("dplyr", type="source")
stevec
  • 41,291
  • 27
  • 223
  • 311