Installing R and R packages

Hey all.

I just popped project bluefin onto a framework 13 laptop a day or two ago, and I’m working to set it up. I’m a statistician and I mostly code in R (via emacs and emacs-speaks-statistics).

I’ve installed R via homebrew (brew install r) and I am now trying to install the r packages from CRAN.

I’m getting this following error:

 install.packages("data.table")
Installing package into ‘/var/home/linuxbrew/.linuxbrew/lib/R/4.4/site-library’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
Warning: failed to download mirrors file (cannot open URL 'https://cran.r-project.org/CRAN_mirrors.csv'); using local file '/home/linuxbrew/.linuxbrew/Cellar/r/4.4.3_1/lib/R/doc/CRAN_mirrors.csv'
Warning: unable to access index for repository https://ftp.osuosl.org/pub/cran/src/contrib:
  cannot open URL 'https://ftp.osuosl.org/pub/cran/src/contrib/PACKAGES'
Warning messages:
1: In download.file(url, destfile = f, quiet = TRUE) :
  URL 'https://cran.r-project.org/CRAN_mirrors.csv': status was 'SSL peer certificate or SSH remote key was not OK'
2: package ‘data.table’ is not available for this version of R

A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages 

I haven’t used homebrew much before, but I’ve been reading about this for most of the evening and it seems like it is often suggested that users avoid installing R with homebrew exactly because of difficulties with R package installation.

So, I think my questions are:

  1. Am I missing something obvious that will make homebrew R on PB work nicely?

  2. Is there a better way for me to be installing R on PB? I believe one option would be for me to install and set up emacs + R in a container. I tested this out a bit by spinning up a fedora container using buddybox, installing R with dnf and then installing packages, all which seemed to work. I also haven’t used containers much and I would prefer to have a solution that didn’t involve regularly spinning up a container. This emacs + R setup is where I spend a significant amount of my time each day and it seems to me that it would have less friction if I had the combination working using flatpak and homebrew.

So far PB has been great and I like a lot of the concepts behind it (thanks devs!) but if I can’t get this to work cleanly for me then I’ll have to find a different distro solution.

thanks,
Aaron

EDIT: since I selected a solution, the thread was locked before I could post an update and thank the responders. Here’s what I was drafting when it was locked:

thanks @stego and @JohnAtl , your suggestions worked like a charm.

the distrobox with arch allowed me to use pacman to install all the system libraries I need (I do a lot of spatial work, and sometimes getting relevant system libs installed and linked up with R can be a pain), R, and emacs. I exported both the R bin and the Emacs app to the system, as you each suggested, and all is working. I can run R from within emacs, read/write to my directories and dropbox, and I can installing R packages, in emacs, etc.

Very slick. Thanks for all the pointers.

1 Like

I assume PB = project bluefin

I suppose you installed emacs via homebrew as well?

There are probably ways to solve this with homebrew, but I’m more a fan of distrobox. With distrobox I can create mutable containers for different tasks. When you are using distrobox, you still have access to your home directory.

Let’s say you want to create a distrobox called “my-r”, then you can run

distrobox create -i ubuntu --name my-r
distrobox enter my-r

and then

# update indices
sudo apt update -qq
# install two helper packages we need
sudo apt install --no-install-recommends software-properties-common dirmngr
# add the signing key (by Michael Rutter) for these repos
# To verify key, run gpg --show-keys /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc 
# Fingerprint: E298A3A825C0D65DFD57CBB651716619E084DAB9
wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
# add the repo from CRAN -- lsb_release adjusts to 'noble' or 'jammy' or ... as needed
sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"
# install R itself
sudo apt install --no-install-recommends r-base

The above instructions are copied from Ubuntu Packages For R - Brief Instructions

After that you can run the R command inside the distrobox.

And if you want to make R available to the outside system, then you can run the following inside the distrobox.

distrobox-export --bin /usr/bin/R

This should allow emacs to find your R interpreter.

1 Like

@stego, thanks for the detailed reply and suggestion and particularly for the info on how to make R from inside distrobox available to the outside system. I’ll give it a shot this evening.

I assume PB = project bluefin

yes

I suppose you installed emacs via homebrew as well?

No, I installed it via flatpak, but I have no problem using homebrew for it if that would be preferable.

I ran arch for a few years, and manjaro for another handful, but I don’t really have any linux experience with package management and installation outside of pacman

Is there a reason to use homebrew over flatpak or vice versa for managing emacs (or any other package) inside project bluefin?

Another former Arch user. Splendid!

Installing editors or IDEs via flatpak is usually a bad idea if you need them to talk to other parts of the system. Flatpak isolates the application from the rest of the OS. That means you won’t be able to see all files and won’t be able to hook up helper programs, unless you install these helper programs with an internal package manager - actually, I’m not even sure if that works. I never tried that.

That’s why bluefin-dx ships with Visual Studio Code on the host. You also have vim (unfortunately not neovim) available on bluefin and bluefin-dx, but that is probably not what you want.

I suggest that you create an archlinux distrobox for your general development work:

distrobox create --image ghcr.io/ublue-os/arch-distrobox  --name programming
distrobox enter programming

and then wait for the default packages to be installed. Next run

sudo pacman -Syu emacs
emacs

The distrobox can directly work with files in your home directory. If you want to install other software for your development, just pacman it. For example:

sudo pacman -S r  # yay, R is in the arch repositories!

Now you can say: “I use arch on Bluefin btw” :smiling_face_with_sunglasses:

1 Like

thanks again, @stego.

seems like I should just get comfy with distrobox and deal with adapting to the different workflow. Having badly broken my arch/manjaro system a few times over the years, I can easily see the benefits of a stable and immutable distro and that is certainly worth a bit of self-evolution.

Just wanted to add, if you (or Future People™) want to run a GUI like R-Studio (or the Emacs gui, I suppose), then you can export that app from the distrobox, and run it from your host gui, as if it were installed there.
From inside the distrobox:

distrobox-export --app emacs

(I don’t actually use emacs, just installed to illustrate, thus the errors.)

2 Likes

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