Impossible to install R package 'sf'

Hello, I am trying to deploy in Binder Hub a Jupyter notebook with an R kernel, that makes use of the ‘sf’ R package. When trying to install it, it fails, because one of the dependencies (package ‘units’) cannot be installed.
I discovered this problem is quite common, and on local platforms it could be overcome by installing “units” in this way:

install.packages("units", configure.args = "--with-udunits2-lib=/PHShome/ks38/.local/lib")

but I have no information on how to do this in the Binder environment.
Any hint?

Here are two, untested, approaches that might be worth your time to try:

  • use apt
    • create an apt.txt
      libudunits2-devx
      
    • while the current version is 2.2.28-3 you’ll might have to figure out the version yourself
    • if the versions are wrong, you have to re-commit and re-build, as apt is called very early as root
  • use conda (specifically, conda-forge)
    • create an environment.yml
    channels:
      - conda-forge
      - nodefaults
    dependencies:
       - r-base # whatever version
       - r-irkernel
       # and all your other leaf r- dependencies
       - r-sf
    
    • the r-sf package depends on r-units depends on udunits2
      • you might still need to specify a version or two
      • if the versions are wrong, you might be able to mamba install different versions of the above packages, and restart your kernel, as the joyvan user (that also runs the kernel, terminals, etc) can change that environment
2 Likes

Thanks for your indications.

I tried to follow the first approach, as I am not an expert in conda.
I created the apt.txt with
libudunits2-dev
(following the instructions in GitHub - r-quantities/units: Measurement units for R) and now, when I check, library units is available, the answer to library(units) is:

udunits database from /usr/share/xml/udunits/udunits2.xml

I also checked all other dependencies of sf, and they are all available.
Nonetheless, sf is not available. After using

install.packages(“sf”)

I also tried to install it by using:

install.packages(“sf”,type=“source”,configure.args = “–with-udunits2-include=/usr/share/xml/udunits”)

and also:

install.packages(“sf”,type=“source”,configure.args = " --with-udunits2-lib=/usr/share/")

but I always failed.

not an expert in conda.

welp, on binder, my experience has become:

  • one can become an expert in a bunch of different things
    • and solve all the problems, given enough time
  • or accept you already are a user of conda
    • and solve 90% of the things with a little searching on conda-forge
    • or create unsurmountable problems in the other 10% that cannot be overcome without coordinating efforts between 20 upstream parties

so if you’re dead in the water debugging cran vs apt, trying a little conda-forge might be worth your time to see which partition this lands you in.

following the instructions

Excellent, docs are good! But beware: as suggested, perhaps the versions don’t match. On that page, it says an exact version needed for the current master branch: depending on which version you want (which you should probably pin down, given these issues) the version of that README (or their test infrastructure) at that version might indicates which exact version of the upstream you need.

install.packages

Once you do get it working, definitely consider adopting the repo2docker well-known file install.R so this all happens during build time and gets cached, as it will save a lot of time and trouble re-building. Solving this in environment.yml will have a similar effect.

but I always failed.

without more log output, we can’t help much, but as not much of a reader of r tea leaves, i can’t guarantee i would know how to interpret them.

The problem seems to be solved.
I checked again on the github site of sf, and found that in Linux not only libudunits2-dev, but also libgdal-dev, libgeos-dev and libproj-dev are required (differently from windows).
So, I added also these packages in the apt.txt and now sf is installed correctly and works.

Thank you for your indications.

Anyway, you are right when you say that I should get experienced in conda. I am since long an R and RStudio user, and only recently I started to move to Anaconda and Python.

2 Likes

Hi, I have been facing the worst experience of running different R packages at Jupytar Notebook. For example; FPP3, tssible, ggplot2. I have tried by ‘install. Packages()’ and also conda environment. Everytime it comes some Nonzero status output and failed to install. I am kind of new to coding. Any help to install these R packages in Jupytar will be highly appreciated.

Just for anyone who visits this later, this conversation was continued in a separate thraed: Use of R packages in Jupytar - #3 by bollwyvl

2 Likes

I am trying to install sf package in R, but it returns error and unable to install the package. The warning message 192.168.l.254 said. I am having a hard time getting sf to install on my computer (Macbook Pro 2017) with the latest version of Rstudio. When I call the command Changing the configuration in R Studio to solve install packages issue . Go To Tools → Global option → Packages. Then uncheck the option “Use secure download method for HTTP”. For other RStudio issues refer to official Troubleshooting Guide here

latest version of Rstudio

If you are running in binder/jupyterhub, you might be the first one to encounter this particular issue. Spefically binder support for rstudio usually lags a bit reacting to whatever they change under the hood, and it may take some time before it works well, if at all with a given version: Run rstudio directly from repo2docker · Issue #533 · jupyterhub/repo2docker · GitHub

If you aren’t running under any jupyter infrastructure, this may not be a fruitful place to get answers (you never know!), but you may want to investigate your options for getting RStudio support more directly or from that community.

1 Like