installing packages in Rstudio on Ubuntu Linux


I am having issues installing packages on my Ubuntu Jammy. I followed the step on the link

I followed instructions for the Jammy. Everything step goes smoothly until last step

install.packages(to_reinstall[,1], dependencies = TRUE, ask = FALSE)

After I entered the above code the error returned was

Error: dbus: Call failed: Launch helper exited with unknown return code 1

Please what is the problem and how to I resolve it? I'm stuck here and I think it's the last step.

What specifically happens when you try to install packages the usual way (i.e., not what is described in the linked answer but just how you would ordinarily do it)?

When I tried installing the normal way using install.packages("tidyverse") or install.packages("tidyverse", dependencies = TRUE) it will brings a bunch of codes on the console. The code is pretty much but I captured the last part of it.

Error: dependencies 'googledrive' , 'googlesheets4' , 'httr', 'ragg' 'rvest' , 'xml2' are not available for package 'tidyverse'

*removing '/home/Farouq/R/x86_64-pc-linux-gnu-library/4.4/tidyverse'

Warning in install.packages : installation of package 'tidyverse' had non-zero exit status

The downloaded source packages are in '/tmp/RtmptEsl3F/downloaded_packages'

Calling library (tidyverse) returned Error in library (tidyverse) : there is no package called 'tidyverse'

Moreover, if I tried to install the dependencies above individually it still the same problem. Additionally, it's not just tidyverse. It happens when I try to install any package.

I have installed R-base 4. and latest version of Rstudio.

I don't know what is going on here, but you could always give pak a try. Assuming you can install at least pak from our repo [1].

[1] All about installing pak. — Installing pak • pak

For the pak it's indicated you support Linux x86_64 R 3.4.0 - R-devel. I'm currently using R-4.4.0 on Linux 22.04 Jammy.

I noticed something else, when I click on Tools > Global Options > Packages > Management

Package Management

:warning: CRAN repositories modified outside package preferences

Could this be the problem? I have uninstalled Rstudio with all its dependencies and reinstalled it afresh thinking it was going to solve the issue.

Yes, that means all versions from R 3.4.0 up to R-devel. Including R 4.4.0 as well.

Okay. Let me try installing a pak and see if it solve the problem.

It's possible that some of the tidyverse dependencies (or some of their dependencies) require one or more system (not R) libraries that you have not installed. If you continue to have problems, try installing one package at a time (for instance, try installing just httr), and see if you encounter any errors. If a package won't install, check for a message about being unable to find a file with the extension ".so". That will point to a Linux library you need but do not have.

I have tried installing one package at a time and it continues. Does anyone experiences this kind of problem? Isn't installing R-base and Rstudio on Ubuntu linux supposed to be simple and seamless? I didn't encounter this kind of problem when I was using Windows.

I've installed and updated on Linux Mint (derived from Ubuntu) with no problems whatsoever. Occasionally I get a "can't find .so" error, which tips me off to a prerequisite package I need to install from the Canonical repository before installing whatever R package triggered the error.

Okay. I have completely removed everything R from my Ubuntu linux including R-base, Rstudio, and all the associated dependencies, packages, and files. I want to try a fresh installation and see. I hope that solves the problem.

The default Linux experience is different from Windows and macOS because CRAN only provides pre-built binaries for Windows and macOS. The errors you are likely seeing on Ubuntu is the packages are failing to build from source because you haven't manually installed the required system libraries.

Options on how you can proceed:

  1. Learn how to read the error messages and determine what libraries you need to install. This is a useful skill in general on Linux, not just for installing R packages. You can usually copy-paste an error message into your favorite search engine and find some ideas. For example, you almost certainly need the system library libxml2 installed, which you can install with sudo apt install libxml2-dev. Another good source of hints is to look up the package on CRAN and look at the suggestions in the field SystemRequirements
  2. Use the Posit Package Manager. Unlike CRAN, it builds binaries for many popular Linux distributions. Here are the setup instructions for Ubuntu Jammy
  3. Use r2u to use APT to download R package binaries. This is what I personally use on Ubuntu. After you follow the setup instructions, you can install the entire tidyverse with a single command sudo apt install r-cran-tidyverse. The setup instructions include the optional step to configure the {bspm} package to highjack install.packages() to actually install the packages via APT. This is super convenient, eg you could run install.packages("tidyverse") directly in the R console, but if you are new to Ubuntu, I wouldn't recommend starting with it. It works great in general, but it occasionally causes me headaches when I want to install non-CRAN packages (eg a local package I am developing or a package only available from GitHub)

Thank you John. I will follow up with your suggestions and see if it works for me. However, before that, when I tried to check if the issue is with the package management this is what I found;

When I click on Tools > Global Options > Packages > Management

Package Management

:warning: warning: CRAN repositories modified outside package preferences

Could this be the problem? See the screenshot.

This could possibly be involved. What do you get when you run getOption("repos")? Do you have a .Rprofile file in your current working directory or your home directory? This is typically where that would be set. See this other thread for advice on how to change your default CRAN mirror URL.

Thank you very much John. Option 3 Use r2u to use APT to download R package binaries worked perfectly for me. I followed the script for my version of Ubuntu Jammy 22.04. I perfectly install complete tidyverse package using sudo apt install r-cran-tidyverse. I also wanted rmarkdown and installed it perfectly using install.packages("rmarkdown). It was super fast.

However, the :warning: warning: CRAN repositories modified outside package preferences is still showing.

When I typed getOption("repos") the output is CRAN "". I tried changing it by using options(repos = c(CRAN = "")) and the output is "". But when I exit Rstudio and login again, the repos changes back before and the warning is still there.

Nevertheless, the issue with the package installation was solved perfectly.

1 Like

Quick follow-up for future readers. I had forgotten how the linux binaries from the Posit Package Manager worked. While downloading a binary will avoid errors during installation, you will still get runtime errors if you haven't manually installed the required dependencies. For example, for the {xml2} package, you still need to manually install libxml2-dev to be able to use it

I had wrongly assumed that the Linux binaries had somehow linked to the system libraries (eg by bundling and statically linking them).

I recently learned of a new R package, {rpsm}, that makes it easier for new users (and users without admin privileges), to use these linux binaries. It automatically downloads the system libraries to a user directory and then edits the RPATH of the R package shared object to search for system dependencies in this user directory. It's ok if you didn't understand that last sentence. The takeway is that using {rspm} you can install the linux binaries and not have to worry about manually installing the system dependencies.

1 Like

This are great solutions. One can choose any of the below depending on the needs and knowledge of Linux.

The use of CRAN as Ubuntu Binaries - r2u is super convenient and fast. One can install packages using APT. However, one needs to watch out for possible errors especially when installing local packages or packages from GitHub.

The use of Posit Package Manager Posit Package Manager is great as it delivers binary packages compatible with one's choice of Linux. However, the user needs to manually install required dependencies and the system requirements if any.

The use of CRAN - Package rspm package is super easy and straight forward. This is also a better choice especially for those starting out in Linux. They don't need to go through the ache of manually installing system requirements as rspm does that automatically for them.

Thank you John for your time, contributions, and pointing out these solutions.

1 Like

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.