We can use the below init script to install the packages in the cluster:
%scala
dbutils.fs.put("dbfs:/databricks/init_scripts/rlib.sh", """
#!/bin/bash
sudo apt-get install -y libudunits2-dev
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get install -y libudunits2-dev libgdal-dev libgeos-dev libproj-dev
sudo apt-get install -y libfontconfig1-dev
sudo apt-get install -y libcairo2-dev
sudo apt-get install -y libprotobuf-dev
sudo apt-get install -y protobuf-compiler
sudo add-apt-repository -y ppa:opencpu/jq
sudo apt-get install -y libjq-dev
sudo apt-get install -y libv8-dev
R -e 'install.packages(c("rgdal", "RJDBC", "sf", "rgeos"), dependencies = T, repos = "https://cran.r-project.org")'
""",true)