GitLab at IIASA

README.Rmd 1.97 KiB
Newer Older
---
output: rmarkdown::github_document
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
```

# FarmDynR

Developed by Hugo Scherer and Marc Müller at Wageningen Economic Research.

<!-- badges: start -->
<!-- badges: end -->

The goal of FarmDynR is to give the user the ability to aggregate FADN data to create representative farms for any grouping available, generate descriptive statistics, and to run FarmDyn from R.

## Requirements
This package requires that you have GAMS and FarmDyn installed. Additionally, the package imports from:
- gdxrrw (remember to load GAMS with `igdx()` with the path to your version of GAMS)

It also suggests:
- stringr

## Installation

You can install the development version of FarmDynR like so:

``` r
 install.packages('https://gitlab.iiasa.ac.at/mind-step/FarmDynR')
```
## Workflow

The workflow for this package is as follows:
1. Read the FADN data into R
2. Run `fadn2fd()` with the FADN data, farmbranch desired, the mapping and the option to save GDX files based on the mapping
    - Yields will be calculated and the FADN data will be prepared
    - Outliers are removed
3. Write batch file with `writeBatch()` and run FarmDyn with `runFarmDynfromBatch()` using the created batch file
  - Optional: Create descriptive statistics for reporting with `fd_desc()` with the farmbranch

## Example


```{r example, eval=FALSE, include=TRUE}
library(FarmDynR)

# Read in FADN data
fadn <- read_fadn("path/to/fadn/data")

# Create mapping
mapping <- list(c("NUTS0", "misc%OrganicCode"), "NUTS0", "NUTS2")

# Create FarmDyn data
fd_data <- fadn2fd(fadn, "Dairy", mapping, save_gdx = FALSE)

# Write batch file
writeBatch("path/to/FarmDyn", mapping, farmIds)

# Run FarmDyn
runFarmDynfromBatch("path/to/batch/file")

# Create descriptive statistics
fd_desc(fd_data)