<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.bwhpc.de/wiki/index.php?action=history&amp;feed=atom&amp;title=BwUniCluster2.0%2FSoftware%2FR%2Fterra_%28R_4.2.1%29</id>
	<title>BwUniCluster2.0/Software/R/terra (R 4.2.1) - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.bwhpc.de/wiki/index.php?action=history&amp;feed=atom&amp;title=BwUniCluster2.0%2FSoftware%2FR%2Fterra_%28R_4.2.1%29"/>
	<link rel="alternate" type="text/html" href="https://wiki.bwhpc.de/wiki/index.php?title=BwUniCluster2.0/Software/R/terra_(R_4.2.1)&amp;action=history"/>
	<updated>2026-04-14T23:20:02Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.17</generator>
	<entry>
		<id>https://wiki.bwhpc.de/wiki/index.php?title=BwUniCluster2.0/Software/R/terra_(R_4.2.1)&amp;diff=13046&amp;oldid=prev</id>
		<title>K Kuck: Created page with &quot; &lt;span style=&quot;color:red&quot;&gt;&lt;b&gt;Note that the instructions provided below refer to R 4.2.1 (but not R 4.3.3)! We are currently updating our guides for R 4.3.3.&lt;/b&gt;&lt;/span&gt;  = General information =   sf and terra allow to use the following tools for handling spatial structures in R   * the &#039;Geospatial&#039; Data Abstraction Library [https://gdal.org/ GDAL]  * Projection/transformation operations from the [https://proj.org/ PROJ] library * Interface to the open source Geometry Engin...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.bwhpc.de/wiki/index.php?title=BwUniCluster2.0/Software/R/terra_(R_4.2.1)&amp;diff=13046&amp;oldid=prev"/>
		<updated>2024-10-28T11:39:27Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot; &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Note that the instructions provided below refer to R 4.2.1 (but not R 4.3.3)! We are currently updating our guides for R 4.3.3.&amp;lt;/b&amp;gt;&amp;lt;/span&amp;gt;  = General information =   sf and terra allow to use the following tools for handling spatial structures in R   * the &amp;#039;Geospatial&amp;#039; Data Abstraction Library [https://gdal.org/ GDAL]  * Projection/transformation operations from the [https://proj.org/ PROJ] library * Interface to the open source Geometry Engin...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Note that the instructions provided below refer to R 4.2.1 (but not R 4.3.3)! We are currently updating our guides for R 4.3.3.&amp;lt;/b&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= General information =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
sf and terra allow to use the following tools for handling spatial structures in R&lt;br /&gt;
 &lt;br /&gt;
* the &amp;#039;Geospatial&amp;#039; Data Abstraction Library [https://gdal.org/ GDAL] &lt;br /&gt;
* Projection/transformation operations from the [https://proj.org/ PROJ] library&lt;br /&gt;
* Interface to the open source Geometry Engine [https://libgeos.org/ GEOS]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
Please enter the following code, presented in the boxes below, directly into your shell/command line on bwUniCluster.&lt;br /&gt;
&lt;br /&gt;
The whole process will take approximately 45 minutes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Preparations ==&lt;br /&gt;
Prepare .R directory (if it does not already exists). This is then filled with information how R should compile the packages (so-called &amp;#039;compilation flags&amp;#039;). These are written (and can be reviewed) into the (text) file Makevars. &lt;br /&gt;
&lt;br /&gt;
If you already have a .R/Makevars file, check whether these flags are already set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat ~/.R/Makevars&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, skip the following block of five commands. If not, please enter the following commands in your shell (command line):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir -p ~/.R&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;CXX14=icpc&amp;quot; &amp;gt; ~/.R/Makevars&lt;br /&gt;
echo &amp;quot;CXX17=icpc&amp;quot; &amp;gt;&amp;gt; ~/.R/Makevars&lt;br /&gt;
echo &amp;quot;CXX14FLAGS=-O3 -fPIC -std=c++14 -wd308 -axCORE-AVX512,CORE-AVX2,AVX -xSSE4.2 -fp-model strict -qopenmp&amp;quot; &amp;gt;&amp;gt; ~/.R/Makevars&lt;br /&gt;
echo &amp;quot;CXX17FLAGS=-O3 -fPIC -std=c++17 -wd308 -axCORE-AVX512,CORE-AVX2,AVX -xSSE4.2 -fp-model strict -qopenmp&amp;quot; &amp;gt;&amp;gt; ~/.R/Makevars&lt;br /&gt;
echo &amp;quot;CXXFLAGS += -wd308&amp;quot; &amp;gt;&amp;gt; ~/.R/Makevars&lt;br /&gt;
echo &amp;quot;PKG_CXXFLAGS += -std=c++14 -wd308&amp;quot; &amp;gt;&amp;gt; ~/.R/Makevars&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Install external programs ==&lt;br /&gt;
&lt;br /&gt;
First, we download the sources of GDAL, PROJ, GEOS and install the three programs.&lt;br /&gt;
&lt;br /&gt;
We will gather them in a folder src, unpack there and then compile.&lt;br /&gt;
&lt;br /&gt;
We strongly recommend to use a interactive session with multiple cores.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
salloc -n 4 -t 60 -p single&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First, provide the source directory (if not yet existing)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir -p ~/src&lt;br /&gt;
cd ~/src&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, download and install PROJ&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PROJ_VER=9.3.1&lt;br /&gt;
wget http://download.osgeo.org/proj/proj-$PROJ_VER.tar.gz&lt;br /&gt;
tar xf proj-$PROJ_VER.tar.gz&lt;br /&gt;
cd proj-$PROJ_VER&lt;br /&gt;
&lt;br /&gt;
mkdir build&lt;br /&gt;
cd build&lt;br /&gt;
&lt;br /&gt;
cmake -DCMAKE_INSTALL_PREFIX=$HOME/sw/R ..&lt;br /&gt;
cmake --build . -j 8&lt;br /&gt;
cmake --build . --target install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, install GDAL&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $HOME/src&lt;br /&gt;
GDAL_VER=3.8.3&lt;br /&gt;
wget http://download.osgeo.org/gdal/$GDAL_VER/gdal-$GDAL_VER.tar.gz&lt;br /&gt;
tar xf gdal-$GDAL_VER.tar.gz&lt;br /&gt;
cd gdal-$GDAL_VER&lt;br /&gt;
&lt;br /&gt;
mkdir build&lt;br /&gt;
cd build&lt;br /&gt;
&lt;br /&gt;
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$HOME/sw/R ..&lt;br /&gt;
cmake --build . -j 8&lt;br /&gt;
cmake --build . --target install&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, install GEOS&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $HOME/src&lt;br /&gt;
GEOS_VER=3.12.1&lt;br /&gt;
wget http://download.osgeo.org/geos/geos-$GEOS_VER.tar.bz2&lt;br /&gt;
tar xf geos-$GEOS_VER.tar.bz2&lt;br /&gt;
cd geos-$GEOS_VER&lt;br /&gt;
&lt;br /&gt;
mkdir _build&lt;br /&gt;
cd _build&lt;br /&gt;
&lt;br /&gt;
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$HOME/sw/R ..&lt;br /&gt;
make -j 8&lt;br /&gt;
ctest -j 8&lt;br /&gt;
make install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Installing the R packages ==&lt;br /&gt;
&lt;br /&gt;
In order to install the two R packages, we need R to understand where we installed the 3 underlying programs, so we export the necessary paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
export LD_LIBRARY_PATH=$HOME/sw/R/lib64:$LD_LIBRARY_PATH&lt;br /&gt;
export PATH=$PATH:$HOME/sw/R/bin&lt;br /&gt;
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$HOME/sw/R/lib64/pkgconfig&lt;br /&gt;
export GDAL_DATA=$HOME/sw/R/share/gdal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Additionally, the R package installation features compilation of built-in C++ code, for which we specify compilation options (&amp;#039;compiler flags&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export CFLAGS=-I$HOME/sw/R/include&lt;br /&gt;
export CXX=&amp;quot;icpc -std=c++11&amp;quot;&lt;br /&gt;
export CXX17=icpc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, we install terra and sf from within R.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module load math/R/4.1.2&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
R -q&lt;br /&gt;
R&amp;gt; install.packages(&amp;quot;terra&amp;quot;)&lt;br /&gt;
R&amp;gt; library(terra)&lt;br /&gt;
terra 1.7.71&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
R&amp;gt; install.packages(&amp;quot;sf&amp;quot;)&lt;br /&gt;
R&amp;gt; library(sf)&lt;br /&gt;
Linking to GEOS 3.12.1, GDAL 3.8.3, PROJ 9.3.1; sf_use_s2() is TRUE&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Preparations to use the terra and sf packages ==&lt;br /&gt;
Since terra and sf depend on the external programs we installed, several environment variables have to be set before using the packages to allow R to address these programs.&lt;br /&gt;
&lt;br /&gt;
We recommend to add the export commands&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=$HOME/sw/R/lib64:$LD_LIBRARY_PATH&lt;br /&gt;
export PATH=$PATH:$HOME/sw/R/bin&lt;br /&gt;
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$HOME/sw/R/lib64/pkgconfig&lt;br /&gt;
export GDAL_DATA=$HOME/sw/R/share/gdal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
to your [[BwUniCluster_2.0_Slurm_common_Features#sbatch_Examples | batch job scripts]] that use terra and sf or to run them directly in the command line if you use an [[BwUniCluster_2.0_Batch_Queues | interactive session]].&lt;/div&gt;</summary>
		<author><name>K Kuck</name></author>
	</entry>
</feed>