Skip to content
Snippets Groups Projects
Commit 2ca12ef1 authored by Mollenhorst, Erwin's avatar Mollenhorst, Erwin
Browse files

Initializing repository, defining arguments and loading screened dataset

parents
No related branches found
No related tags found
No related merge requests found
Data/
.Rhistory
### Stratified sampling of n records out of screened dataset based on intensity and soil types
# Creator: Erwin Mollenhorst
## 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.0.2
# RStudio 1.3.959
### 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()
# Define arguments
vYear <- 2021 # year of KLW records
vIntLim <- c(12.5, 17.5, 22.5)
vNormSoil<- 1.00 # fraction of the farm that has certain soiltype, otherwise category = 'overig' (other)
## Define directories
vRoot <- paste0("W:/PROJECTS/WLR_KringloopWijzer/data ", vYear)
vDir_data <- file.path(vRoot, "Screeningsresultaten")
vDir_results <- file.path(vRoot, "TestSet")
if (!dir.exists(vDir_results)) {dir.create(vDir_results)}
# Loading screened dataset
vList <- list.files(vDir_data)
ifelse(length(grep(paste0("KLW", vYear,"_opgeschoond.rda"), vList)) == 1,
load(file = file.path(vDir_data, vList[grep(paste0("KLW", vYear,"_opgeschoond.rda"), vList)])),
stop("More than one or no .rda file present in vDir_data")
)
rm(vList)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment