10

I need to run 3.6 on debian stretch - I followed the instructions here:

https://cran.r-project.org/bin/linux/debian/

and used this repo:

http://lib.stat.cmu.edu/R/CRAN/bin/linux/debian stretch-cran35/

I was able to install it. But 2 packages I need, r-cran-caret and r-cran-ggplot2 will not install:

# apt-get install r-cran-ggplot2
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 r-cran-ggplot2 : Depends: r-api-3
                  Depends: r-cran-digest but it is not going to be installed
                  Depends: r-cran-gtable (>= 0.1.1) but it is not
going to be installed
                  Depends: r-cran-plyr (>= 1.7.1) but it is not going
to be installed
                  Depends: r-cran-reshape2 but it is not going to be installed
                  Depends: r-cran-scales (>= 0.4.1) but it is not
going to be installed
                  Depends: r-cran-tibble but it is not going to be installed
                  Depends: r-cran-lazyeval but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

Is there a way to get these 2 packages for my environment?

kjetil b halvorsen
  • 1,206
  • 2
  • 18
  • 28
Larry Martell
  • 3,526
  • 6
  • 40
  • 76

2 Answers2

2

You're missing dependencies and apt-get tells you that these are broken. You need to remove the broken dependencies from your R library, which should be in /usr/lib/R/site-library.

Why don't you just install it directly within R?

install.packages(c("caret", "ggplot2"), dependencies = TRUE)

As you have mentioned you want to use docker: See the littler package by Dirk Eddelbuettel: https://github.com/eddelbuettel/littler especially install2.r function and it's option -d

For examples how others use it see the rocker docker images.

Another edit: If you decide to use littler, I think you'll need this syntax

install2.r -d TRUE caret ggplot2
RBirkelbach
  • 101
  • 8
  • I am not using a R session. I am calling R from python with rpy inside a docker container, so I need the package available at the OS level. I tried to install it from within R and it worked. But I need them to install with apt when I make the docker image. – Larry Martell Aug 06 '19 at 22:09
  • 1
    Why don't you post your dockerfile to let us see what's wrong? You should check how the Dirk Eddelbuettel and Carl Boettiger do it in the rocker images: https://github.com/rocker-org/rocker – RBirkelbach Aug 07 '19 at 18:27
  • 1
    Use `rscript` to install – Hong Ooi Aug 07 '19 at 18:41
  • Because it's taking some 3 minutes to install. In a CI environment, it's not really worth the while. – jjmerelo Mar 05 '21 at 08:46
2

I am not sure if this will solve your problem.

sudo dpkg --configure -a

In these cases I find it easier to use aptitude

sudo apt install aptitude    
sudo aptitude install r-cran-ggplot2

of course you can try the same with caret if ggplot2 works.

A question is however if you load R in a terminal and try to install these packages within R what kind of error messages do you get, if you get any?

type R in a terminal and after it loads type

install.packages("ggplot2",dependencies=TRUE)

what error messages do you get when you do that?

Another common problem is that the version of a package you are trying to install does install in the version of R you are using. In that case you have to download the package from cran, untar it and install from local files.

open a terminal and type R then inside the session type

packageurl <- "https://cran.r-project.org/src/contrib/ggplot2_3.2.0.tar.gz"
install.packages(packageurl, repos=NULL, type="source", dependencies=TRUE)

If you have the common problem of versioning this command will hopefully not bother checking the version of ggplot and the version of R.

Alternatively if you do not want to explicitly start an R session type in terminal

wget https://cran.r-project.org/src/contrib/ggplot2_3.2.0.tar.gz
R CMD INSTALL ggplot2_3.2.0.tar.gz repos=NULL type="source" dependencies=TRUE