# Error to install sf package under R

**URL:** <https://discourse.jupyter.org/t/error-to-install-sf-package-under-r/32395>\
**Category:** Zero to JupyterHub on Kubernetes\
**Created:** [February 3, 2025, 10:09am UTC](https://discourse.jupyter.org/t/error-to-install-sf-package-under-r/32395 "2025-02-03T10:09:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiao\_wang](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/xiao_wang/32/14242_2.png) [@xiao\_wang](https://discourse.jupyter.org/u/xiao_wang)\
**Post date:** [February 3, 2025, 10:09am UTC](https://discourse.jupyter.org/t/error-to-install-sf-package-under-r/32395/1 "2025-02-03T10:09:51Z")

</div>

I configured Jupyterhub with datascience-notebook ([Selecting an Image — Docker Stacks documentation](https://jupyter-docker-stacks.readthedocs.io/en/latest/using/selecting.html)). When I try to install sf package for R from Terminal by inputing install.packages(“sf”), I got error:

```auto
>install.packages(“sf”) 
        ................................
	installing to /opt/conda/lib/R/library/00LOCK-s2/00new/s2/libs
	** R
	** data
	*** moving datasets to lazyload DB
	** inst
	** byte-compile and prepare package for lazy loading
	** help
	*** installing help indices
	*** copying figures
	** building package indices
	** testing if installed package can be loaded from temporary location
	** checking absolute paths in shared objects and dynamic libraries
	** testing if installed package can be loaded from final location
	** testing if installed package keeps a record of temporary installation ath
	* DONE (s2)
	ERROR: dependency ‘units’ is not available for package ‘sf’
	* removing ‘/opt/conda/lib/R/library/sf’
	
	The downloaded source packages are in
	        ‘/tmp/RtmpPcFudJ/downloaded_packages’
	Updating HTML index of packages in '.Library'
	Making 'packages.html' ... done
	Warning messages:
	1: In install.packages("sf") :
	  installation of package ‘units’ had non-zero exit status
	2: In install.packages("sf") :
	  installation of package ‘sf’ had non-zero exit status
>

```

I try to install package units, but it requires package udunits…

The Jupyterhub is installed from helm3: [JupyterHub helm charts | JupyterHub’s Helm chart repository](https://jupyterhub.github.io/helm-chart/) in Microk8s (1.29/stable). Microk8s is deployed on Ubuntu 22.04 LTS.

Any idea?

---

<div class="post-metadata">

**Author:** ![minrk](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/minrk/32/13_2.png) [@minrk](https://discourse.jupyter.org/u/minrk)\
**Post date:** [February 6, 2025, 8:40am UTC](https://discourse.jupyter.org/t/error-to-install-sf-package-under-r/32395/2 "2025-02-06T08:40:15Z")

</div>

It is unliklely to be related to jupyterhub, but rather the R installation in your image. It looks like installation of `units` failed, you could try by starting with installing units directly:

```r
install.packages("units")

```

and see if you get a more informative error. I get:

```auto
configure: error:
--------------------------------------------------------------------------------
  Configuration failed because libudunits2.so was not found. Try installing:
    * deb: libudunits2-dev (Debian, Ubuntu, ...)
    * rpm: udunits2-devel (Fedora, EPEL, ...)
    * brew: udunits (OSX)
  If udunits2 is already installed in a non-standard location, use:
    --configure-args='--with-udunits2-lib=/usr/local/lib'
  if the library was not found, and/or:
    --configure-args='--with-udunits2-include=/usr/include/udunits2'
  if the header was not found, replacing paths with appropriate values.
  You can alternatively set UDUNITS2_INCLUDE and UDUNITS2_LIBS manually.

```

which suggests there is a missing dependency that you need to install first.

---

<div class="post-metadata">

**Author:** ![xiao\_wang](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/xiao_wang/32/14242_2.png) [@xiao\_wang](https://discourse.jupyter.org/u/xiao_wang)\
**Post date:** [February 6, 2025, 1:11pm UTC](https://discourse.jupyter.org/t/error-to-install-sf-package-under-r/32395/3 "2025-02-06T13:11:21Z")

</div>

Thanks for the reply.  
When I do install.packages(“units”), I get exactly what you have. It looks like I need to install libudunits-dev, but I don’t know how to install.  
I try to do: install.packages(“libudunits”) and install.packages(“libudunits-dev”). Both don’t work. I check all installed packages by: installed.packages()[,], I don’t find out packages of libudunits or libudunuts-dev.  
My Jupyterhub version is Ubuntu 22.04. Please see the output:

```auto
jovyan@jupyter-xiaowang:~$ cat /etc/os-release 
PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

```

---

<div class="post-metadata">

**Author:** ![Paul2708](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/paul2708/32/14207_2.png) [@Paul2708](https://discourse.jupyter.org/u/Paul2708)\
**Post date:** [February 6, 2025, 1:55pm UTC](https://discourse.jupyter.org/t/error-to-install-sf-package-under-r/32395/4 "2025-02-06T13:55:20Z")

</div>

`libudunits2` is not a Julia but a [Debian package](https://packages.debian.org/de/sid/libudunits2-dev).  
You have to install it using `sudo apt install libudunits2-dev`.

However, since you probably don’t have root rights inside the container, the Docker image has to install the dependency.

---

<div class="post-metadata">

**Author:** ![xiao\_wang](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/xiao_wang/32/14242_2.png) [@xiao\_wang](https://discourse.jupyter.org/u/xiao_wang)\
**Post date:** [February 6, 2025, 2:11pm UTC](https://discourse.jupyter.org/t/error-to-install-sf-package-under-r/32395/5 "2025-02-06T14:11:41Z")

</div>

Thanks. You are right. I have no root privilege under Jupyterhub.

```auto
jovyan@jupyter-xiaowang:~$ sudo ls
sudo: The "no new privileges" flag is set, which prevents sudo from running as root.
sudo: If sudo is running in a container, you may need to adjust the container configuration to disable the flag.

```

So how can I install ?

I install Jupyterhub by:

```auto
microk8s helm3 repo add jupyterhub https://jupyterhub.github.io/helm-chart/

```

---

<div class="post-metadata">

**Author:** ![minrk](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/minrk/32/13_2.png) [@minrk](https://discourse.jupyter.org/u/minrk)\
**Post date:** [February 7, 2025, 7:47am UTC](https://discourse.jupyter.org/t/error-to-install-sf-package-under-r/32395/6 "2025-02-07T07:47:48Z")

</div>

Another option might be to install the package with conda:

```auto
mamba install r-sf

```

---

<div class="post-metadata">

**Author:** ![xiao\_wang](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/xiao_wang/32/14242_2.png) [@xiao\_wang](https://discourse.jupyter.org/u/xiao_wang)\
**Post date:** [February 7, 2025, 10:40am UTC](https://discourse.jupyter.org/t/error-to-install-sf-package-under-r/32395/7 "2025-02-07T10:40:57Z")

</div>

I do: mamba install r-sf and it looks like to install successfully.  
I can see the package sf by:

```auto
> installed.packages()[,]
.......................
sf NA NA NA "yes" "4.3.3"

```

But I got error when using package sf by:

```auto
> library(sf)
Error: package or namespace load failed for ‘sf’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/opt/conda/lib/R/library/sf/libs/sf.so':
  /opt/conda/lib/R/library/sf/libs/../../../../libgdal.so.36: undefined symbol: sqlite3_total_changes64
>

```

---

<div class="post-metadata">

**Author:** ![xiao\_wang](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/xiao_wang/32/14242_2.png) [@xiao\_wang](https://discourse.jupyter.org/u/xiao_wang)\
**Post date:** [February 7, 2025, 12:48pm UTC](https://discourse.jupyter.org/t/error-to-install-sf-package-under-r/32395/8 "2025-02-07T12:48:16Z")

</div>

I solve it by: `mamba update sqlite`.  
But I don’t understanding why sqlite doesn’t be updated when `mamba install r-sf`?

---

<div class="post-metadata">

**Author:** ![minrk](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/minrk/32/13_2.png) [@minrk](https://discourse.jupyter.org/u/minrk)\
**Post date:** [February 13, 2025, 8:30am UTC](https://discourse.jupyter.org/t/error-to-install-sf-package-under-r/32395/9 "2025-02-13T08:30:30Z")

</div>

this suggests that perhaps gdal doesn’t express a sufficiently strict dependency on libsqlite. Alternately, it is _possible_ that earlier `install.packages()` commands may have installed multiple versions of things, leading to an issue.
