From 12914a52e274151b802896578df97258182a2098 Mon Sep 17 00:00:00 2001
From: Erwin Mollenhorst <erwin.mollenhorst@wur.nl>
Date: Fri, 12 Aug 2022 15:22:50 +0200
Subject: [PATCH] Initial script, loading first sheet

---
 01_Master.R | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 01_Master.R

diff --git a/01_Master.R b/01_Master.R
new file mode 100644
index 0000000..a6e34da
--- /dev/null
+++ b/01_Master.R
@@ -0,0 +1,27 @@
+## remove (almost) everything in the working environment.
+## You will get no warning, so don't do this unless you are really sure.
+rm(list = ls())
+
+# R version 4.2.1
+# RStudio 2022.07.0+548 
+
+### ipak function: install and load multiple R packages.
+### check to see if packages are installed. Install them if they are not,
+### then load them into the R session.
+IPAKCD <- function(pkg){
+  new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
+  if (length(new.pkg)) 
+    install.packages(new.pkg, dependencies = TRUE)
+  sapply(pkg, library, character.only = TRUE, logical.return = TRUE)
+}
+
+#   Set working directory
+IPAKCD(c("rstudioapi", "data.table", "openxlsx", "dplyr"))
+setwd(dirname(getActiveDocumentContext()$path))
+getwd()
+
+# Inlezen Sheet voorraden file
+vDataVrd <- read.xlsx(xlsxFile = "data/20220811_MeststromenData.xlsx",
+                      sheet = "Begin en Eindvoorraad")
+vDataVrd$CodeCat <- as.factor(paste(vDataVrd$Mestcode, vDataVrd$Mestcategorie))
+summary(vDataVrd$CodeCat)
-- 
GitLab