Installation of the R library sf on Ubuntu
Problem
The R package sf (Simple Features for R) provides so-called Simple Features to R code. Simple Features is a set of standards for geographic features and is at Wikipedia described thus:Simple Features (officially Simple Feature Access) is a set of standards that specify a common storage and access model of geographic features made of mostly two-dimensional geometries (point, line, polygon, multi-point, multi-line, etc.) used by geographic databases and geographic information systems. It is formalized by both the Open Geospatial Consortium (OGC) and the International Organization for Standardization (ISO). (Simple Features)
The sf library has many dependencies including some system libraries that need to be installed outside of R using whatever package system is available on the platform of choice.
The problem now arises on Ubuntu (and maybe other Linux systems as well), as Ubuntu comes with the MariaDB database as the standard, but the gdal dependency of sf requires the Oracle controlled MySQL.
On Ubuntu this looks like the following
The following packages have unmet dependencies: libmariadb-dev : Conflicts: libmysqlclient-dev but 8.0.42-0ubuntu0.24.04.1 is to be installed Breaks: libmysqlclient-dev but 8.0.42-0ubuntu0.24.04.1 is to be installed E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.
Solution
A quick solution is to remove the MariaDB installation, which off course requires, that no other libraries and program dependens on it, and then proceed with installing the needed system libraries, where gdal will pull in the MySQL dependency.
sudo apt autoremove libmariadb-dev sudo apt -y update && sudo apt install -y libudunits2-dev libgdal-dev libgeos-dev libproj-dev
Then sf can be installed and validated
install.packages("sf") library(sf) # Load built-in shapefile of North Carolina counties nc <- st_read(system.file("shape/nc.shp", package = "sf")) # Print a summary of the sf object print(nc)
The not-so-quick solution would be to install gdal from source and configure it to exclude support for MySQL and rely on PostgreSQL and SQLite for database support.
Note bene (meta)
So, in these early years of the LLM-era, how did I solve the above? What made the penny drop? What did I bring to the table and what did ChatGPT bring?
I remember that I've had this problem before, although a very long time ago. Back then, I remember doing quite a bit of installing from source to solve it. This time around, I began on the webpage for sf, and then used my distant remembrance of apt and dpkg and the fact that MariaDB is an Open Source and vendor-free fork of MySQL from a while back.
To use apt and dpkg for probing the system I had to turn to ChatGPT for the actual commands, as the details had been long forgotten.
So, in conclusion, my experience and knowledge of a few central tools put me on the right path and I could ask my assistant to help me with the forgotten details.
References
Simple Features for R. (n.d.). Retrieved June 24, 2025, from https://r-spatial.github.io/sf/index.html
Simple Features. (2024). In Wikipedia. https://en.wikipedia.org/w/index.php?title=Simple_Features&oldid=1246035065