0

I installed 'tidyverse' but it was showing an error.

Error: package or namespace load failed for ‘tidyverse’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
 there is no package called ‘fansi’

So I installed 'fansi', and it was showing below.

> install.packages("fansi")

  There is a binary version available but the source version is later:
      binary source needs_compilation
fansi  0.4.2  0.5.0              TRUE

Do you want to install from sources the package which needs compilation? (Yes/no/cancel) yes

But I received below error message.

* installing *source* package ‘fansi’ ...
** package ‘fansi’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
ERROR: compilation failed for package ‘fansi’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1/Resources/library/fansi’
Warning in install.packages :
  installation of package ‘fansi’ had non-zero exit status

I tried to run 'tidyverse' again, but still having the same error. Do you know what's causing this and how to solve?

Phil
  • 7,287
  • 3
  • 36
  • 66
Lucy
  • 17
  • 7
  • You probably lack the Rtools program v2, try downloading it with https://cran.r-project.org/bin/windows/Rtools/rtools40v2-x86_64.exe – Bruno Jun 01 '21 at 00:43
  • 1
    Or if you are running on mac it probably needs some library to compile it, in this case it looks like xcrun try to run xcode-select --install on your terminal – Bruno Jun 01 '21 at 00:45
  • If you just want the tidyverse and don't care for the latest stuff just pick the option "no" to not compile from source, it should download version 0.4.2 just fine – Bruno Jun 01 '21 at 00:46
  • What is Xcode and how can I install it? I selected 'no' for "Do you want to install from sources the package which needs compilation?" this time, and got some conflict this time. – Lucy Jun 01 '21 at 00:59
  • ── Conflicts ─────── tidyverse_conflicts() ── x dplyr::filter() masks stats::filter() x dplyr::lag() masks stats::lag() – Lucy Jun 01 '21 at 01:00
  • That is it you have successfully installed the tidyverse, it warns you that some old r functions will be hidden if you still need them just type stats::lag() for example, good luck! – Bruno Jun 01 '21 at 01:09

1 Answers1

1

In general as a new user, it is much less hassle to just select "No", when presented with the question Do you want to install from sources the package which needs compilation? (Yes/no/cancel) in R.

Explanation of the question by R and responses

The question Do you want to install from sources the package which needs compilation? (Yes/no/cancel) is telling you that one (or more) of the packages you are trying to install has a newer version than what is available as a binary. To understand what this means, you need to understand a bit about the R package ecosystem.

CRAN

The default location where packages are installed from is called CRAN (Comprehensive R Archive Network). This is a web-server (actually many servers world-wide), that has a copy of many R packages. When packages are written for R, they are initially written and submitted to CRAN as source code. The source code submitted to CRAN is then compiled into binary packages for the Windows and Mac OS operating systems.

You could think of it like a clothing shop. You can go to the shop and get a jacket for cold weather, or a hat for sunny weather, or lots of other options.

Binary Packages

Packages are compiled into binaries because they have several advantages: they enable faster installation by end users as the user doesn't need to compile the source code for themselves, which saves them time. They are also easier for users to manage as a user doesn't require extra software or tools, and they tend to be more stable. The downsides however are that the binaries are specific to a particular system, usually an Operating system, and sometimes even particular versions of an operating system. Compiling a package from source takes time, especially if it's a large package. Binaries also (potentially) don't contain the latest version of the code, so there may be bugs that haven't been fixed, or it may be missing new features or additions.

The CRAN Process

When CRAN receives an updated package, it can take a few days to get around to compiling the source code into a binary. In the meantime, if users try to install that package, the message you observed is displayed, giving the user the choice of installing the binary, which is usually much quicker, but may not have some new features or may contain bugs that haven't yet been fixed, or the source code version which is the latest version, but requires the extra tools you discovered.

In the context of a store analogy, you could think of this as new stock for the clothing shop. They have received the new stock, but haven't yet put it out on the racks. You can come back in a few days, or you can find the box (which will need a tool like a knife to open) and unpack it yourself, and then get the item.

Installing from source

As mentioned in the comment by @Bruno, you will need to install Xcode to install packages from source on MacOS or rtools on Windows. Most of the time installing these additional tools is all that's required to build packages from source, but sometimes things may not work so smoothly, which is why installing binaries is usually better.

Aditional note about conflicts

The note you received about conflicts is entirely normal when loading the tidyverse. It's there to alert you to the fact that there are multiple functions with the same name that come from different packages, and this may cause problems if you don't realise. In most cases you don't need to worry about it, but is pretty easy to solve if there are issues.

Sam Rogers
  • 787
  • 1
  • 8
  • 19