R

R must be version 4.0 or higher.

Clone this repository

On the command line: navigate to your desired folder location and then enter git clone https://github.com/JGCRI/tradecast.git

If using GitHub Desktop: Go to https://github.com/jgcri/gcamfaostat and click the green “Code” button. Then click “Open with GitHub Desktop”.

Loading the tradecast package

Open the tradecast folder you just cloned and double-click the gcamfaostat.Rproj file. RStudio should open the project.

If you have not installed devtools before, first enter the following into the R console

install.packages("devtools")

Then to load the tradecast package, enter:

devtools::load_all()

Package dependencies

You may also need to install package dependencies, for example using:

devtools::install_deps()

For this reason, we suggest using renv, described below.

Optional renv – currently included in GCAM 6.0 and gcamdata release

NOTE THAT SETTING UP/RESTORING RENV WHILE ON VPN CAN CAUSE ERRORS HIGHLY RECOMMENDED TO AVOID VPN DURING SET-UP

renv is an R package for dependency management. Using it will save a private R library with the correct versions of any package dependencies.

The steps to use renv include:

  1. Install renv package (if not already installed)
install.packages( "https://cran.r-project.org/src/contrib/Archive/renv/renv_0.12.5.tar.gz", repos = NULL, type = "source" )
  1. Initialize a local library (may prompt you to restart your R session)
renv::init( bare = TRUE)
  1. Install the correct packages (this may take some time)
renv::restore()

You should now be set to run the driver without running into any package version issues. Note that if you have completed these steps once, your R session should automatically connect to this private library when you open gcamdata.Rproj. If your R session doesn’t connect to this (for example, if you changed branches), you can run the following to reconnect to this private library:

renv::activate()