25

I am on an Ubuntu 18.04 machine with R version 3.5.1, installed following this link. I am trying to install the CRAN package rJava, which I do the following way (as seen here):

sudo apt-get install r-cran-rjava

However, I get this:

The following packages have unmet dependencies:
 r-cran-rjava : Depends: r-api-3.4
E: Unable to correct problems, you have held broken packages.

But when I try:

sudo apt-get install r-api-3.4

I get:

E: Package 'r-api-3.4' has no installation candidate

How to overcome this problem with r-api-3.4? Basically, I need to install rJava to be able to install and use XLConnect... In Ubuntu 16.04, I had no problems whatsoever...

EDIT:

Apparently, r-api-3.4 should be provided by r-base-core. I do have r-base-core installed in its newest version, why do I still see errors then?

DaniCee
  • 2,397
  • 6
  • 36
  • 59
  • why not go through the R console to install packages? – chinsoon12 Jul 10 '18 at 03:31
  • 2
    I tried that first, but it gave errors, then I saw https://stackoverflow.com/questions/7765429/unable-to-install-r-package-in-ubuntu-11-04 , https://askubuntu.com/questions/858961/install-rjava-on-ubuntu-failed , https://stackoverflow.com/questions/3311940/r-rjava-package-install-failing – DaniCee Jul 10 '18 at 03:49
  • and https://askubuntu.com/questions/176115/what-is-the-best-way-of-installing-the-r-package-xlconnect – DaniCee Jul 10 '18 at 03:52
  • Basically, I need `rJava` to be able to use `XLConnect`... In Ubuntu 16.04 I had no problems – DaniCee Jul 10 '18 at 03:52
  • 1
    That produces the exact same output `The following packages have unmet dependencies: r-cran-rjava : Depends: r-api-3.4 E: Unable to correct problems, you have held broken packages.` – DaniCee Jul 10 '18 at 03:54
  • might be because those have not been created for >= R-3.5? – chinsoon12 Jul 10 '18 at 03:56
  • Then how to overcome that? – DaniCee Jul 10 '18 at 03:56
  • Apparently `r-api-3.4` should be provided by `r-base-core`... why am I seeing this errors then? – DaniCee Jul 10 '18 at 04:45
  • maybe its because u r using R-3.5.1 – chinsoon12 Jul 10 '18 at 05:22
  • So what should be the way to get rJava to work with R-3.5.1? – DaniCee Jul 10 '18 at 05:25
  • check out this thread: https://stat.ethz.ch/pipermail/r-sig-debian/2018-May/002832.html. you might want to use R-3.4 for now – chinsoon12 Jul 10 '18 at 05:37

1 Answers1

31

The API versions are provided by r-base-core. The reason is that binary packages (sometimes) depend on the R version, for which they have been build. This way you can only install packages that fit together.

In your case you have packages from the main Ubuntu repository (r-base-core 3.4.x providing r-api-3.4 and r-cran-rjava requiring r-api-3.4) and from a custom PPA (r-base-core 3.5.y providing r-api-3.5). One option would be to only use the version from Ubuntu, i.e. R 3.4. Another solution is to add an additional PPA:

sudo add-apt-repository ppa:marutter/c2d4u3.5
sudo apt-get update

After that a version of r-cran-rjava requiring r-api-3.5 should be available. See also http://rubuntu.netlify.com/post/2018-05-25-announcing-c2d4u3-5/ and http://rubuntu.netlify.com/post/2018-06-11-r-3.5-on-debian-and-ubuntu-update/.

Finally, you always have the possibility to install the R packages directly from CRAN. That is currently the only possibility when you are using the CRAN supplied R backports on Debian.

Ralf Stubner
  • 26,263
  • 3
  • 40
  • 75
  • thanks for the answer! I guess I will stick to R 3.4 for now – DaniCee Jul 11 '18 at 02:16
  • 2
    I didn't like the going back to 3.4 version as I would have to reinstall all the other packages, and didn't understand any of the links given in this answer. I have r 3.5 and adding the addition PPA mentioned helped. Along with the [main instructions here for installing rjava](https://github.com/hannarud/r-best-practices/wiki/Installing-RJava-(Ubuntu)) and restarting R. My installation procedure is [here](http://agent18.github.io/R-installation.html) and my installation of packages is documented [here](http://agent18.github.io/learning-R.html) , search for packages. – agent18 Oct 22 '18 at 17:57
  • After installing the ppa (thanks for that!) I also found it necessary to update libquantlib: `sudo apt install libquantlib0*` – Robert McDonald Dec 04 '18 at 00:26
  • This link was also helpful: https://rtask.thinkr.fr/installation-of-r-3-5-on-ubuntu-18-04-lts-and-tips-for-spatial-packages/ – Phil Sep 08 '20 at 10:29