How to force binary installation from the RSPM when running R from a system terminal in Ubuntu 22.04?

If I try to install a package from the RSPM when running RStudio all works as expected and the package is installed from a binary, but if I try to install the same package when running R from a system terminal the package installs from "source" even if it is downloaded from the same RSPM repository. What option do I need to change to force binary installation in Ubuntu 22.04?

1 Like

I’ve found it easy to end up with different site-package directories. Since then, however, I’ve discovered the r2uk package which installs pre-compiled binaries and is maintained by the famous Dirk Eddelbuettel.

Thanks, I'm aware of that project but I'm not looking for a walkaround, I want to know what option is set by the RStudio IDE that forces binary installation on Linux

You'll probably need to configure your R user agent header so that it includes the R version and OS information again. Since R 3.6, R replaces the default user agent with a generic libcurl user agent (like libcurl/7.68.0) when using the default libcurl download method, so there's no way to know what R version to serve a binary package for. This user agent info is only necessary on Linux, where R doesn't officially support installation of binary packages, unlike Windows and macOS.

The RStudio IDE works around this user agent issue by setting a custom user agent that doesn't get stripped:

> getOption("HTTPUserAgent")
[1] "RStudio Desktop (2022.10.0.68); R (4.2.1 x86_64-w64-mingw32 x86_64 mingw32)"

If you install R from RStudio's precompiled R binaries, you'll also avoid the issue as those binaries have a custom user agent set by default:

> getOption("HTTPUserAgent")
[1] "R/4.2.1 (ubuntu-22.04) R (4.2.1 x86_64-pc-linux-gnu x86_64 linux-gnu)"

But if you've compiled R from source or installed R from the default distro package, and are running R from the terminal, you'll need to manually configure a user agent in a startup file like Rprofile.site. The user agent can be in any format, as long as it includes R's original HTTP user agent and does not begin with "R (". For RSPM, we typically recommend a format like this:

# Set the default HTTP user agent
options(HTTPUserAgent = sprintf("R/%s R (%s)", getRversion(), paste(getRversion(), R.version["platform"], R.version["arch"], R.version["os"])))
3 Likes

Thanks, that is exactly the information I was looking for

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.