From 0874ec32eeb213e42508b12567db2aac53c4d463 Mon Sep 17 00:00:00 2001
From: Daniel Vedder <daniel.vedder@idiv.de>
Date: Mon, 2 Jan 2023 17:23:39 +0100
Subject: [PATCH] Made `datadir` configurable in `analyse_nature.R`

---
 run.sh                        |  8 ++++----
 src/analysis/analyse_nature.R | 14 +++++---------
 2 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/run.sh b/run.sh
index 8641b43..7cd3d64 100755
--- a/run.sh
+++ b/run.sh
@@ -1,11 +1,11 @@
 #!/bin/bash
 ## A short shell script to test the current development version of Persephone.
 
-if [[ -d "test_results" ]]
+if [[ -d "temp_results" ]]
 then
-    rm -r test_results
+    rm -r temp_results
 fi
 
-./run.jl -o test_results -s 2
+./run.jl -o temp_results -s 2
 
-src/analysis/analyse_nature.R
+src/analysis/analyse_nature.R temp_results
diff --git a/src/analysis/analyse_nature.R b/src/analysis/analyse_nature.R
index 8b2f275..c176b9f 100755
--- a/src/analysis/analyse_nature.R
+++ b/src/analysis/analyse_nature.R
@@ -12,7 +12,7 @@ library(terra) #https://rspatial.github.io/terra/index.html
 
 autorun = TRUE ## automatically run all analyses?
 
-datadir = "test_results" ## "results" by default
+datadir = "results" ## "results" by default, can be specified via commandline
 popfile = "populations.csv"
 indfile = "individuals.csv"
 mapfile = "landcover_jena.tif"
@@ -58,14 +58,10 @@ visualiseMap = function() {
 
 ## If autorun is set, run the experiment specified via commandline argument
 if (autorun) {
+    ## the last commandline argument is interpreted as the output directory
+    ##TODO make map files configurable
+    arg = commandArgs()[length(commandArgs())]
+    if (dir.exists(arg)) datadir = arg
     populationTrends()
     visualiseMap()
-    ##TODO set variables from commandline arguments
-    ## arg = commandArgs()[length(commandArgs())]
-    ## if (arg %in% c("tolerance", "habitat", "mutation", "linkage","tolerance_long")) {
-    ##     experiment = arg
-    ##     results = loadData(experiment)
-    ##     plotAll(results)
-    ## }
-    ## else { print(paste("Unknown experiment" , arg)) }
 }
-- 
GitLab