From 05212a68a27cd70a4153bb39c19d585312a14e45 Mon Sep 17 00:00:00 2001
From: "WUR\\simon083" <wolfram.simon@wur.nl>
Date: Thu, 26 Aug 2021 15:40:47 +0200
Subject: [PATCH] Update function_collection.R

external function script
---
 Functions_cifos/function_collection.R | 34 +++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/Functions_cifos/function_collection.R b/Functions_cifos/function_collection.R
index e4df8ba..cbcfeb1 100644
--- a/Functions_cifos/function_collection.R
+++ b/Functions_cifos/function_collection.R
@@ -4,6 +4,38 @@ easypackages::packages(c("tidyverse", 'sf', 'raster','sp','dplyr','spatialEco',
                          "plyr"))
 
 
+
+# Loading data ------------------------------------------------------------
+
+# Functions loading dbf SPAM files
+FUNload_list_dbf_SPAM <- function(path, type) {
+  pattern <- switch (type,
+                     "harv" = "_H_",
+                     "phys" = "_A_",
+                     "prod" = "_P_") 
+  path <- list.files(path = path, 
+                     full.names = TRUE,
+                     pattern = pattern)
+  l_dbf <- lapply(path, foreign::read.dbf)
+  names(l_dbf) <- basename(path)
+  return(l_dbf)
+}
+
+# Functions loading dbf veggie and nuts Monfreda files
+FUNload_list_monfreda <- function(path, type) {
+  pattern <- switch (type,
+                     "harv" = "_HarvestedAreaHectares",
+                     "phys" = "_HarvestedAreaHectares",
+                     "prod" = "_Production")
+  path <- list.files(path = path, 
+                     full.names = TRUE,
+                     pattern = pattern)
+  l_csv <- lapply(path, read.csv)
+  names(l_csv) <- basename(path)
+  return(l_csv)
+}
+
+
 # Crop variable conversion ------------------------------------------------
 # Calculate production from yields and area - here: suitable yields
 FunProdCalcSuit = function(Area,Yield){
@@ -29,3 +61,5 @@ Fun_aggregate = function(suitability_dat){
     dplyr::summarise(SAR_ha = sum(SAR_ha), 
                      SPR_ton = sum(SPR_ton))
 } 
+
+
-- 
GitLab