Programming
Problems installing the devtools package
The devtools package is an indispensable tool for R users, especially those involved in package development or needing to install packages directly from GitHub. It streamlines the process of building, loading, and checking R packages, making it a cornerstone for many data scientists and developers. However, encountering problems installing the devtools package is a surprisingly common hurdle that can frustrate even experienced R users. These issues often stem from complex dependencies, system-specific configurations, or missing external tools. Understanding the root causes of these installation challenges is the first step toward a smoother R development workflow.
Understanding Why devtools Installation Can Be Tricky
The devtools package, while incredibly powerful, doesn’t operate in a vacuum. It relies heavily on external system tools and other R packages to perform its functions, particularly when compiling source code. This reliance is often the primary source of devtools installation issues. Unlike many other R packages that are pre-compiled binaries readily available from CRAN (the Comprehensive R Archive Network), devtools often requires your system to have the necessary compilers and build tools to process its own source code, or the source code of packages it helps install.
For Windows users, this typically means having RTools installed and correctly configured. RTools provides the GNU toolchain (gcc, make, etc.) that R uses to compile C, C++, and Fortran code. On macOS, the equivalent is Xcode Command Line Tools. Without these fundamental system components, R cannot compile source packages, leading to errors like “installation of package ‘xyz’ had non-zero exit status.” This fundamental requirement sets devtools apart from simpler package installations and is a frequent point of failure when trying to install devtools.
Furthermore, devtools has a web of dependencies on other R packages, some of which might have their own specific requirements or version constraints. Conflicts between these dependencies, or outdated versions of R itself, can also manifest as perplexing installation errors. For instance, a common problem arises when a required dependency needs a newer version of R than what you currently have installed, or when there’s a clash between a CRAN version of a package and a version from Bioconductor. Addressing these layered dependencies is crucial for successful installation.
Common Hurdles and Practical Solutions for devtools Installation
When you face problems installing the devtools package, the culprit is usually one of a few common issues related to your system environment or R setup. Identifying these issues is key to resolving them efficiently. Many users initially attempt install.packages("devtools"), only to be met with cryptic error messages. Let’s break down the most frequent obstacles and their straightforward solutions.
One of the most prevalent issues, particularly for Windows users, is the absence or misconfiguration of RTools. RTools is a collection of tools necessary for building R packages from source. Without it, R cannot compile the underlying C/C++ code that many packages, including devtools itself, rely on. Similarly, macOS users need to ensure they have the Xcode Command Line Tools installed, which provide a similar set of compilers and build utilities. To install Xcode Command Line Tools, simply open your terminal and run xcode-select --install. For RTools, download the appropriate version for your R installation from the CRAN website and follow the installation instructions carefully, ensuring it’s added to your system’s PATH.
Another significant hurdle is R version compatibility. devtools is actively maintained and often requires a relatively recent version of R. If your R installation is significantly outdated, you might encounter errors due to API changes or dependency requirements. Always ensure your R version is up-to-date. According to the official RStudio documentation, “keeping your R and RStudio versions current is a best practice that often resolves many package installation headaches before they even begin.” This simple step can often preempt many complex issues. Additionally, ensure that your internet connection is stable and that any proxy or firewall settings aren’t blocking access to CRAN or GitHub repositories, as these can silently fail installations.
Permission errors are also a common annoyance. If R is installed in a system-protected directory, or if you lack administrative privileges, R may not be able to write new packages to the library path. This can often be circumvented by running RStudio or R as an administrator (on Windows) or by ensuring your package library path is set to a user-writable directory. You can check your library paths using .libPaths() and add a new one with .libPaths("path/to/your/custom/library") if needed. Resolving these environmental factors is crucial for smooth devtools package installation.
Step-by-Step Troubleshooting for devtools Installation Issues
When facing persistent devtools installation issues, a systematic approach to troubleshooting can save significant time and frustration. Instead of randomly trying solutions, follow these steps to diagnose and resolve common problems. These steps cover the most frequent causes of installation failures and provide actionable solutions.
- Update R and RStudio: Ensure you are running the latest stable versions of R and RStudio. Outdated versions often lack compatibility with newer package features or have known bugs that have since been patched. You can download the latest R from CRAN and RStudio Desktop from their official website.
- Install/Update System Build Tools:
- For Windows: Download and install the correct version of RTools that matches your R version. During installation, ensure the option to add RTools to the system PATH is selected. After installation, restart RStudio.
- For macOS: Open Terminal and run
xcode-select --install. Follow the prompts to install the Xcode Command Line Tools. - For Linux: Install development packages specific to your distribution (e.g.,
sudo apt-get install r-base-devfor Debian/Ubuntu, orsudo yum install R-develfor Fedora/CentOS).
- Clean R Package Cache and Reinstall Dependencies: Sometimes, corrupted or incomplete package downloads can cause issues. Clear your package cache if your IDE supports it, or manually delete the temp directory for R. Then, try reinstalling devtools and its core dependencies: ```
install.packages(“remotes”) install.packages(“curl”) install.packages(“openssl”) install.packages(“devtools”)
The `remotes` package is often a more robust alternative for installing from GitHub and is a dependency of `devtools` itself. - Check for Proxy/Firewall Issues: If you are in a corporate network, proxy settings or firewalls might block access to CRAN or GitHub. Configure R to use your proxy by setting environment variables like http_proxy and https_proxy. Consult your IT department for the correct settings.
- Run RStudio as Administrator (Windows) / Check Permissions: If you’re getting “permission denied” errors, try running RStudio with administrative privileges. Alternatively, ensure your R package library path (
.libPaths()) is set to a directory where your user account has full write permissions. You can change your default library path if necessary.
By systematically working through these steps, you can isolate and resolve most common problems installing the devtools package. Remember to restart your R session or RStudio after making system-level changes, especially after installing RTools or Xcode tools.
Advanced Strategies and Best Practices --------------------------------------While the basic troubleshooting steps resolve most devtools installation issues, some scenarios require a deeper understanding of R’s package management and system interactions. Employing advanced strategies and adopting best practices can prevent future problems and streamline your R development workflow.
For complex dependency trees or when installing packages from non-CRAN sources, the remotes package offers a more flexible and robust Question & Answer :
I wish to use the devtools package. I’ve run the following commands:
> install.packages("devtools", dependencies = TRUE) .... > library(devtools) Error in library(devtools) : there is no package called ‘devtools’
What am I doing wrong?
Edit: Here are the results of re-running the install.packages command after restarting the session.
> install.packages("devtools", dependencies = TRUE) Installing package into ‘/home/evanaad/R/x86_64-pc-linux-gnu-library/3.0’ (as ‘lib’ is unspecified) --- Please select a CRAN mirror for use in this session --- Warning: dependencies ‘roxygen2’, ‘BiocInstaller’, ‘rstudio’ are not available also installing the dependencies ‘httr’, ‘RCurl’ trying URL 'http://cran.at.r-project.org/src/contrib/httr_0.2.tar.gz' Content type 'application/x-gzip' length 50183 bytes (49 Kb) opened URL ================================================== downloaded 49 Kb trying URL 'http://cran.at.r-project.org/src/contrib/RCurl_1.95-4.1.tar.gz' Content type 'application/x-gzip' length 870915 bytes (850 Kb) opened URL ================================================== downloaded 850 Kb trying URL 'http://cran.at.r-project.org/src/contrib/devtools_1.4.1.tar.gz' Content type 'application/x-gzip' length 105214 bytes (102 Kb) opened URL ================================================== downloaded 102 Kb * installing *source* package ‘RCurl’ ... ** package ‘RCurl’ successfully unpacked and MD5 sums checked checking for curl-config... no Cannot find curl-config ERROR: configuration failed for package ‘RCurl’ * removing ‘/home/evanaad/R/x86_64-pc-linux-gnu-library/3.0/RCurl’ ERROR: dependency ‘RCurl’ is not available for package ‘httr’ * removing ‘/home/evanaad/R/x86_64-pc-linux-gnu-library/3.0/httr’ ERROR: dependencies ‘httr’, ‘RCurl’ are not available for package ‘devtools’ * removing ‘/home/evanaad/R/x86_64-pc-linux-gnu-library/3.0/devtools’ The downloaded source packages are in ‘/tmp/RtmptvmTrA/downloaded_packages’ Warning messages: 1: In install.packages("devtools", dependencies = TRUE) : installation of package ‘RCurl’ had non-zero exit status 2: In install.packages("devtools", dependencies = TRUE) : installation of package ‘httr’ had non-zero exit status 3: In install.packages("devtools", dependencies = TRUE) : installation of package ‘devtools’ had non-zero exit status
As per damienfrancois’s suggestion, I installed libcurl4-gnutls-dev and the problem was solved.
EDIT (@dardisco)
In your shell:
apt-get -y build-dep libcurl4-gnutls-dev apt-get -y install libcurl4-gnutls-dev