How to Install an R Package from Source

Installing package from source R

After spending about an hour, thanks to @user20650 and @GWD I was able to solve my problem as follows:

  • I previously had R 3.5.3, I upgraded to the latest version 3.6.2
  • Steps to upgrade R if you already have it: tutorial 1 and tutorial 2
  • After having R 3.6.2, I used RGui rather that RStudio to install Hmisc
  • I typed in the GUI console: install.packages("Hmisc"); it prompts you for a message about compilation, I clicked on NO

How do I install an R package from the source tarball on windows?

I know this is an old question but it came up first in my Google search for this same question, even though I knew the answer I just wanted something to copy and paste. Which makes it worth improving the answer for future reference. So here is what works for me:

Install rtools, then:

install.packages(path_to_file, repos = NULL, type="source")

Installing an R package from local unzipped folder

If it is an unzipped Windows binary (e.g., from CRAN), you can just copy and paste the entire package directory into your library folder. You could also, presumably, use file.copy() to do so if you wanted to do it within R. install.packages() is failing (weirdly) because you're giving it something other than the typical package source or zipped binary that it is expecting.

To build an R package from source fails: Win10, RStudio

This is more of a work around than a proper answer. The alternative to installing and building from source is to install a pre-built binary. If one is not available, you can build it remotely.
In this case, for the package of interest for me, rundel/livecode on github, I:

  1. Forked the repo (in this case rundel/livecode). This step might be optional.
  2. Downloaded the tar.gz (remotes::install_github("markbneal/livecode") which doesn't install it, but the error tells you where it saves the .tar.gz file locally.
  3. Used rhub to build the package binary for windows, go to this website https://builder.r-hub.io/ and upload your tar.gz file, ensuring rhub has your email address (click "advanced" button to provide your email address as alternate - you will need to validate it). That emails me a zip 5 minutes later.
  4. Then copy the livecode folder in the zip that is emailed to me to my "R packages" folder location.
    Package should now work for you, in my case library(livecode)

Edited six months later when I had to use this process again!

R package long time to install - Source or Binary type

Source installs are the most up-to-date, where binary packages may lag by "some time". This is reflected in your output, where your R-3.6 sees 1.4.6 as the most recent though 1.5.3 source is available.

Some ways around this:

  1. install.packages("stringi", type="binary") should find the closest version and install it without needing to compile it.

  2. Download one of the .zip files (since you're on windows) from the CRAN page for stringi page and then use install.packages("path/to/stringi_1.5.3.zip"). However, they only have binary versions for R-4.0, not for R-3.6 ("r-oldrel"), so ... it may complain, or it may install and fail spectacularly when you most need the package in the future (and are on the plane without an internet connection).

  3. According to a blog post on RStudio, you can use their public CRAN-like mirror to install binary packages for: linux (not available on CRAN) and for older releases of R (also not available on CRAN).

In your case, since you said your getOption("pkgType") is "both", that means 'use binary if available and current, otherwise try source' (from ?install.packages), which matches the 1.4.6-vs-1.5.3 issue I mentioned first.



Related Topics



Leave a reply



Submit