---
title: "Installation"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Installation}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
resource_files:
  bib/mapspam.bib
bibliography: bib/mapspamc.bib
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

To run `mapspam2globiom`, you need to install several several R packages and GAMS.

### Essential R packages

Several R packages are required to run `mapspam2globiom`: 

- [mapspamc](https://michielvandijk.github.io/mapspamc/). This packages implements the Spatial Production Allocation Model (SPAM) [@You2006; @You2009; @You2014a; @Yu2020] in R [@VanDijk2023]. The ouput are a set of crop distribution maps that are used as input in the `mapspam2globiom` package.

- To interface between R and GAMS the gdxrrw package is required. Unfortunately, this package is not available on CRAN and therefore has to be installed manually. The package can be found [here](https://github.com/GAMS-dev/gdxrrw), which also presents instructions on how to install the package. Several functions in `mapspamc` use gdxrrw to read and save GAMS gdx files and check whether the package and GAMS are installed.

- [tidyverse](https://cran.r-project.org/web/packages/tidyverse/index.html) [@Wickham2019] is the name for a set of packages that work in harmony to facilitate data preparation and processing, most importantly dplyr, purrr, tidyr and ggplot2. Some of them are used by `mapspamc` and will be installed automatically when the package is installed for the first time and were not installed before. 

- [sf package](https://cran.r-project.org/web/packages/sf/index.html) [@Pebesma2018] is a package to process spatial data in vector (polygon) format.

- [terra package](https://cran.r-project.org/web/packages/raster/index.html) [@Hijmans2022] is a package to process spatial data in raster format.



## GAMS

`mapspam2globiom` creates several GAMS gdx files for which [GAMS](https://www.gams.com/) is required. GAMS is a modelling system and language designed for mathematical optimization. The GAMS system and solvers can be downloaded from the GAMS website. 

- [Download and install GAMS](https://www.gams.com/download)


## References
