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'
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.
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:
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
Use the Posit Package Manager. Unlike CRAN, it builds binaries for many popular Linux distributions. Here are the setup instructions for Ubuntu Jammy
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
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: CRAN repositories modified outside package preferences is still showing.
When I typed getOption("repos") the output is CRAN "https://cloud.r-project.org". I tried changing it by using options(repos = c(CRAN = "https://cran.rstudio.com")) and the output is "https://cran.rstudio.com". 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.
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.
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.