Occasionally after install.packages():
Do you want to install from sources the package which needs compilation? (Yes/no/cancel)
What are the implications of not installing a package that needs compilation from source(s)?
What I know so far
I guess it's safer to always select 'Yes', and I suspect this may reinstall (/update) shared libraries or extensions (e.g. c, c++, fortran). Also some very general ideas/advantages listed here
Related
I recently began using RStudio on a Linux system (Ubuntu 20.4) after having used it exclusively on Windows. I realized pretty quickly that a major difference between the two is that R will automatically locate and download non-R dependencies on Windows, but will not do so on Linux. Searching for the dependencies of any given package is easy enough and I'm comfortable with downloading non-R packages through the terminal. What I'm still struggling with, though, is identifying which packages are R packages and which packages are non-R packages and I haven't found a thread that outlines how to do this. I could certainly spend some time googling each, but, as an example, ggpubr alone has over 95 dependent packages that it uses. How can I efficiently determine which non-R dependencies a package needs?
You need to read the DESCRIPTION file. It has a free-form field called SystemRequirements that describes non-standard requirements of the package.
You can see this on the CRAN page, or use the utils::packageDescription() function to see it if you can get the package installed. For example,
cat(utils::packageDescription("rgl")$SystemRequirements)
#> OpenGL, GLU Library, XQuartz (on OSX),
#> zlib (optional), libpng (>=1.2.9, optional), FreeType (optional),
#> pandoc (>=1.14, needed for vignettes; if not present,
#> markdown package will be used)
Created on 2022-04-16 by the reprex package (v2.0.1)
On CRAN this is shown on https://cloud.r-project.org/web/packages/rgl/index.html .
Many packages test for their dependencies and try to give helpful messages about how to install their dependencies if they aren't found. Others just fail to install, sometimes with fairly inscrutable error messages.
The reason this can be easier on Windows is that binary versions of packages are available for Windows. The nice people at CRAN find and install a large number of system dependencies on their own systems, then use those to build binary versions of the package that statically link the required libs. However, some packages can't statically link; they need DLLs of the libs to be installed on the system. Those ones can be quite hard for Windows users to install.
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?
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.
I am creating my first package, which shall be installed through Github. I thought that Rtools was needed only for the person creating it. However, people that tried to install it using Github were asked to update Rtools. Is this really necessary?
Doing some research, I found this: https://community.rstudio.com/t/missing-rtools-should-i-be-worried/27817
One of the answers says the following:
"This means that if you are going to install packages that need
compilation, you also have to install Rtools in your system. "
This is the repo with the package: https://github.com/datazoompuc/PNAD_Covid/tree/master/R/datazoom_pnad_covid
What does this actually mean? How do I know that my package needs compilation?
I thought that Rtools was needed only for the person creating it.
Yes, if and only if you distribute it as a binary. Then the creator uses Rtools to compile and link, and the user just installs, and enjoys.
That is how CRAN works as CRAN compiles for Windows users.
GitHub, however, is foremost a source repository so the installation from GitHub is using a source mode ... and every user will need to compile, and hence have Rtools. (Unless the package and all its depedencies are R-code only.)
You can also have a package repository on GitHub using e.g. the drat package to create it, but that is getting us a little further from the original question.
Your package "needs compilation" — i.e. needs Rtools to install from source (on Windows) — if it contains C or Fortran components, i.e. if you have anything in the src/ directory of your package ...
If you, the package author, don't know if you have C or Fortran code as part of your package, then you almost certainly don't.
It's quite possible that devtools is being overzealous, i.e. detecting that users have a not-most-current Rtools and suggesting (requiring??) that they update it, even though it's not needed for this installation.
Apologies if this has been answered before but I can't find any related answer.
Is there an option to force install packages in R and their dependencies in a user library even if they exists on a common/system library?
For example, package "viridis" requires "viridisLite", however if the later is installed on the system library it will not be automatically installed on the user library when installing "viridis". This can cause some errors.
I am making an R package with Rcpp. It works fine on my machine which has Rtools installed. But recently, I tried to install my package locally on a different machine (Windows) and got a compiling error. The reason was that on that machine there was no g++ compiler (for Windows, g++ is provided with Rtools). After installing Rtools, it worked just fine.
So the question is, if I upload it to CRAN, does it still requires users to install Rtools by hand? Or does the function install.package() detect and install Rtools for them?
Also, if you guys know some packages written with Rcpp, please let me know. I'd like to take a look how it works.
So the question is, if I upload it to CRAN, does it still requires users to install Rtools by hand?
No.
Or does the function install.package() detect and install Rtools for them?
No.
What happens is that CRAN builds pre-compiled binary files that can be installed by Windows and MacOS users without the need for compilers and related tools.
Also, if you guys know some packages written with Rcpp, please let me know. I'd like to take a look how it works.
rr <- devtools::revdep("Rcpp")
length(rr) ## 907
or see the Rcpp page on CRAN.
Users, e.g. people who download it via install.package(), are actually downloading a "compiled" version of the packaged called a binary that is maintained by CRAN. They will only ever need a copy of R.
On the other hand, Developers, e.g. people who are creating it, require development tools that are system specific. For those on the Windows platform, they must have a local install of Rtools on their machine. For developers on macOS, they must have their own copies of gfortran binaries and xcode developer line tools.
Lastly, there are many such Rcpp packages available to look to for inspiration...
See the Rcpp CRAN page
Pick a package and then look up the source at http://github.com/cran/packagename
View an annotated list by Dirk here.