eddelbuettel / r2u

CRAN as Ubuntu Binaries

Home Page:https://eddelbuettel.github.io/r2u

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using within RStudio

robjhyndman opened this issue · comments

While this works using R running in a terminal, I'm getting an error when installing from within RStudio:

> install.packages("hts")
Error in install.packages : cannot connect to the system package manager

On KDE Neon 5.25 (based on Ubuntu 20.04). Using R 4.2.1 and RStudio 2022.07.1 Build 554.

That's known and documented (somewhere) and really unfortunate: bspm hooks around the base R functions, but RStudio (and also renv) all do their own thing so no bspm integration.

Sad as that may be for users of those interfaces, apt still works.

Actually, re-reading. If install.packages does not work maybe the sudo part does not work. Paging @Enchufa2...

Counter-example from my Ubuntu 22.04 laptop with a standard bspm installation (but with sudo=TRUE) and a standard RStudio nightly from my PPA (shown in the screenshot) fetching them two times a week.

image

(Sorry for posting an image, copying text form the console here does not seem to work well.)

So we would need more details from you about your setup that fails given my existence proof

How to do a standard bspm installation with sudo=TRUE? I tried
sudo apt install r-cran-bpsm
and
sudo R CMD INSTALL bspm_0.3.9.tar.gz
but same result.

This usually happens when bspm is installed in the user library or, as a system package, it is not properly configured (and I think that r-cran-bspm in c2d4u is not; I pinged Michael about this, but got no response), see e.g. cran4linux/bspm/issues/40. So the solution is:

  1. Most importantly, uninstall any trace of bspm copies in your system, especially anything in the user dir, which is loaded with higher priority.
  2. Install bspm using sudo:
sudo Rscript --vanilla -e 'install.packages("bspm", repos="https://cran.r-project.org")'

BTW, we implemented a warning suggesting this fix (v0.3.9.1) but never rolled an update. :( Now CRAN submissions are closed, so maybe in August. I'll add a troubleshooting section to the README in the meanwhile.

Also, one may need

$ tail -3 /etc/R/Rprofile.site 
suppressMessages(bspm::enable())
options(bspm.sudo=TRUE)

$

which the sudo install may add -- it has been a while for me.

Nope, the bspm.sudo option is mainly for non-root containers. I suspect we are talking about a desktop installation here, and this option would interfere.

Are you sure it interferes? Replying (on last-in-Ontario day) from laptop which a) has r2u via bspm for all CRAN content and b) that option and c) no issues whatsoever.

(Also just ran grep -c and I appear to have serverd over 10k deb files since the weekly log rotation (early Sunday). So getting to over 2k/day which is nice.)

Actually maybe because I use Graham's wajig as a wrapper I already have root anyway and it may just be a no-op. Then again it also did not get in the way in the example I posted above.

Yes, I'm sure. This option was added with the container use case in mind, and it is documented as follows:

Note that, if you want to fall back to sudo in a non-interactive session, you need to set options(bspm.sudo=TRUE).

I.e., for non-interactive sessions with password-less sudo. It does not get in the way when you have root access anyway. But it does for the D-Bus mechanism.

For more details, here's where it gets in the way:

https://github.com/Enchufa2/bspm/blob/718eaa73ddec51d863beaf9f437663e2d1eab7d5/R/bridge.R#L43-L51

If sudo is preferred (bspm.sudo=TRUE), then the D-Bus call never happens. It you have root access in the first place, then the direct route is taken.

The problem was fixed when I re-installed bspm using

sudo Rscript --vanilla -e 'install.packages("bspm", repos="https://cran.r-project.org")'

and then removed options(bspm.sudo=TRUE) from Rprofile.site. Now install.package() uses apt install in both RStudio and R in a terminal.

Thanks for confirming! Here's a link for future reference: https://enchufa2.github.io/bspm/#cannot-connect-to-the-system-package-manager

Thanks for confirming. If you have suggestions about how/where we should state this more prominently on the r2u side please do let us know.

Maybe add something after the last para of the "Usage" section in the Readme to explain

  1. bspm must be installed via sudo Rscript ...
  2. Add bspm::enable() should be added to Rprofile.site.

Although I don't know how widely this applies. At least it worked for Ubuntu 20.04.

Thanks -- I'll try to add this this weekend.

I've also updated the installation instructions for Ubuntu in the bspm's README to recommend the installation from CRAN with sudo, see cran4linux/bspm@9d940eb.

This usually happens when bspm is installed in the user library or, as a system package, it is not properly configured (and I think that r-cran-bspm in c2d4u is not; I pinged Michael about this, but got no response), see e.g. Enchufa2/bspm/issues/40. So the solution is:

  1. Most importantly, uninstall any trace of bspm copies in your system, especially anything in the user dir, which is loaded with higher priority.
  2. Install bspm using sudo:
sudo Rscript --vanilla -e 'install.packages("bspm", repos="https://cran.r-project.org")'

Do you have to have tips to effectively complete step 1? Thank you.

You mean uninstalling bspm? You can always rely on installed.packages():

> ip <- installed.packages()
> ip[ ip[,"Package"] == "bspm", 1:3]
     Package LibPath                         Version 
bspm "bspm"  "/usr/local/lib/R/site-library" "0.3.10"
bspm "bspm"  "/usr/lib/R/site-library"       "0.3.5" 
> 

Does that help? On this machine it tells me two locations of bspm installations.

@eddelbuettel Thank you very much. It definitely does! I'll now follow the proposed solution to the problem of the system not being able to connect to the system package manager.

Ok, keep us posted. I also heard from @Enchufa2 that there may be a fix in RStudio because it had to do with whether Rprofile.site is or is not read consistently. I mostly work outside of RStudio when I update my packages so I would not know -- but I do run the nightlies so I could test if we need a fresh "yes / no" on this.

@eddelbuettel It is unfortunately still not working for me.

  • I located the bspm package in my system using the method you shared with me.
  • Then I deleted the folder using sudo rm -rf bspm
  • Then, I reinstalled bspm with the code provided above:

sudo Rscript --vanilla -e 'install.packages("bspm", repos="https://cran.r-project.org")'

  • Finally, I added suppressMessages(bspm::enable()) to the bottom of /etc/R/Rprofile.site

Is there anything else I could try or is there any piece of information you need?

My distribution is Pop OS, which is currently based on Ubuntu 22.04.

Which version of RStudio are you running? (Should be under Help -> About)

I actually run the daily builds, but I haven't got the newest one. My current version is:

2022.12.0 Build 310

Did you install the required dependencies? I.e.,

$ sudo apt-get update && sudo apt-get install python3-{dbus,gi,apt}

@eddelbuettel BTW, these are not mentioned in the README of this repo.

@gueyenono On the laptop on which I use r2u as the default, I just removed a package (on the command-line via sudo dpkg --purge r-cran-rcppspdlog) and then (in RStudio) called install.packages("RcppSpdlog") on its R name and got the r2u binary back thanks to bspm. Worked like a charm inside RStudio. I am running 2022.12.0 Build 295 (and update on this machine every few days as I have a 'local PPA' with a twice-a-week cron job). (I have to host RStudio locally as the binaries are too large for GitHub). I will double check the website to update the RStudio language. (I also just checked that it works via the 'Packages' pane -- that also seems to work though fewer messages seems to make it to the console. dpkg -l still shows a reinstall.) So I think this all works.

@Enchufa2 Yes, I should update that too. In the beginning I always relied upon a r-cran-bspm binary I provided that had the dependencies. Now we show the (simpler for me ;-) ) sudo Rscript ... installation so we have add this hint. Will do.

@Enchufa2 Yes, I installed all the required dependencies. I also would like to note that when I don't add options(bspm.sudo = TRUE) to /etc/R/Rprofile.site, I get an error saying:

Error: dbus: Call failed: Could not activate remote peer: unit failed.

Also, if I want to restart the entire setup process from scratch, is wiping off the bspm package from my system the only thing to do? Thank you.

@gueyenono For the record I do NOT have that (any more). I used to, but @Enchufa2 patiently conviced me that we can avoid the need for bspm.sudo = TRUE. As I understand it (and it has been months on this laptop) the key is sudo Rscript -e 'install.packages("bspm")'. That gives me bspm in /usr/local/lib/R/site-library which for me (and unless changed, all Debian/Ubuntu machines with the r-base-core binary) is first (and hence "winning" entry) in .libPaths()

Is it possible at all that these may cause my issues?

When I add the first repository with sudo add-apt-repository ppa:marutter/rrutter4.0, I get the following warnings and errors. My lack of solidified experience with Linux is the reason for me not being able to troubleshoot the prerequisite steps myself. I was wondering if this had to do with me not being able to use r2u?

Err:25 https://ppa.launchpadcontent.net/mattrose/terminator/ubuntu jammy Release 404 Not Found [IP: 185.125.190.52 443]
Err:26 https://ppa.launchpadcontent.net/tj/bugfixes/ubuntu jammy Release 404 Not Found [IP: 185.125.190.52 443]
W: https://qgis.org/ubuntu/dists/jammy/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
N: Skipping acquire of configured file 'main/binary-i386/Packages' as repository 'https://qgis.org/ubuntu jammy InRelease' doesn't support architecture 'i386'
E: The repository 'https://ppa.launchpadcontent.net/mattrose/terminator/ubuntu jammy Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: The repository 'https://ppa.launchpadcontent.net/tj/bugfixes/ubuntu jammy Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

Yes, very likely. You should try to take care of it. I think my script (and the Dockerfile) do. It's a bit of a pain that it changed between focal and jammy.

FWIW, on my laptop (with the 'personal PPA' for RStudio, and docker and brave and whatnot) -- no warnings whatsoever. This matters!

edd@ahmad:~$ sudo apt update
Ign:1 https://dirk.eddelbuettel.com/ppa-rstudio ./ InRelease
Hit:2 https://dirk.eddelbuettel.com/ppa-rstudio ./ Release   
Hit:3 http://us.archive.ubuntu.com/ubuntu jammy InRelease
Hit:5 http://us.archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:6 http://us.archive.ubuntu.com/ubuntu jammy-backports InRelease
Hit:7 http://security.ubuntu.com/ubuntu jammy-security InRelease       
Hit:8 https://download.docker.com/linux/ubuntu jammy InRelease       
Hit:9 https://brave-browser-apt-release.s3.brave.com stable InRelease 
Ign:10 https://r2u.stat.illinois.edu/ubuntu jammy InRelease                    
Hit:11 https://dl.google.com/linux/chrome/deb stable InRelease             
Hit:12 https://r2u.stat.illinois.edu/ubuntu jammy Release                   
Hit:13 https://cloud.r-project.org/bin/linux/ubuntu jammy-cran40/ InRelease 
Hit:15 https://ppa.launchpadcontent.net/edd/misc/ubuntu jammy InRelease
Hit:16 https://apt.syncthing.net syncthing InRelease      
Hit:14 https://packagecloud.io/slacktechnologies/slack/debian jessie InRelease 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
1 package can be upgraded. Run 'apt list --upgradable' to see it.
edd@ahmad:~$ 

@Enchufa2 README (and docs/) and scripts update.

@eddelbuettel Well noted then. Thank you very much for all the hard work and help. Many thanks to @Enchufa2 as well.