r-hub / r-minimal

Minimal Docker images for R
155 stars 33 forks source link

Installing sf package in r-minimal? #50

Closed chris31415926535 closed 2 years ago

chris31415926535 commented 2 years ago

Thanks for this great resource, and sorry if this is a basic question: Is there a documented way to install the R package sf on top of r-minimal?

I'm building a dockerized web app for geospatial analysis using the sf package, and I'd like to see if I can use r-minimal because of its tiny footprint.

Unfortunately, sf has several build-time dependencies that aren't (I think) available through the apk package manager. I've managed to work through several them one by one (e.g. installing udunits2 from source), but now I'm missing proj_api.h which is a known and tricky issue.

So I'm stuck, and wondered if this is a solved problem. Any advice welcome.

gaborcsardi commented 2 years ago

I added an example for sf: https://github.com/r-hub/r-minimal/blob/master/examples/sf/Dockerfile

chris31415926535 commented 2 years ago

Thank you!! This is great!! I was on the right track but not quite there, and this is really invaluable.

However, to get it to build on my machine I have to edit the Dockerfile at https://github.com/r-hub/r-minimal/blob/master/examples/sf/Dockerfile to replace the step:

RUN installr -d \
        -t "openssl-dev linux-headers gfortran proj-dev gdal-dev sqlite-dev geos-dev" \
    -a "libssl1.1 proj gdal geos expat" \
    sf

With the following almost certainly less-efficient step that doesn't remove any dev packages and uses R's install.packages() function:

RUN installr -c -a "openssl-dev linux-headers gfortran proj-dev gdal-dev sqlite-dev geos-dev libssl1.1 proj gdal geos expat"
RUN R -q -e 'install.packages("sf", repos = "https://cloud.r-project.org")'

The original Dockerfile gives me this error:

#11 8.193 Installing sf
#11 10.10
#11 20.67 ✔ Updated metadata database: 2.33 MB in 6 files.
#11 20.67
#11 20.67 ℹ source packages are missing from Bioconductor
#11 20.68 ℹ Updating metadata database
#11 25.35 ✔ Updating metadata database ... done
#11 25.35
#11 37.85 Error:
#11 37.85 ! error in pak subprocess
#11 37.85 Caused by error in `res_add_defaults(entries)`:
#11 37.85 ! Wrong entry types: `built (logical, expected character)`
#11 37.85 ---
#11 37.85 Backtrace:
#11 37.85 1. pak::pkg_install(commandArgs(TRUE))
#11 37.85 2. pak:::remote(function(...) get("pkg_install_make_plan", asNamespace("pak"))(...)…
#11 37.85 3. err$throw(res$error)
#11 37.85 ---
#11 37.85 Subprocess backtrace:
#11 37.85  1. base::withCallingHandlers(cli_message = function(msg) { …
#11 37.85  2. get("pkg_install_make_plan", asNamespace("pak"))(...)
#11 37.85  3. prop$solve()
#11 37.85  4. private$plan$solve(policy = private$policy)
#11 37.85  5. pkgdepends:::pkgplan_solve(self, private, match.arg(policy))
#11 37.85  6. self$resolve()
#11 37.85  7. pkgdepends:::pkgplan_resolve(self, private)
#11 37.85  8. pkgdepends:::synchronise(self$async_resolve())
#11 37.85  9. asNamespace("pkgcache")$synchronise(...)
#11 37.85 10. base::stop(priv$value)
#11 37.85 11. global (function (e) …
#11 37.85 Execution halted

I'm not sure why the one works and not the other. For what it's worth I'm running Docker version 20.10.14 on Ubuntu 20.04.3 LTS using Windows Subsystem for Linux on Windows 10 Home 10.0.19044 Build 19044.