2 Setup

  1. Start by downloading or cloning the targets-issa project.
    • Download the zipped project: targets-issa.zip
    • Clone: git clone https://github.com/iSSA-guild/targets-issa/
  2. Open the RStudio project in the targets-issa repository.
  3. Install required packages.
    • renv::restore()
    • If any packages error while installing, make sure you have the required system dependencies installed. Then try installing those again with install.packages('package_name')
    • Run renv::restore() again
  4. Run the targets workflow. It is defined in the script _targets.R.

While the workflow is running, it will print the progress. A green dot indicates targets that run successfully, a red X indicates targets that hit an error and a green check mark indicates targets that are skipped because they are already up to date. After you have run the workflow, you’ll be to the output of individual targets with tar_read(target_name). For example, let’s read the first five lines from the prepared example relocations.

tar_read(locs_prep)[1:5]
x_ y_ t_ id tar_group
593216 4738712 2011-02-11 23:06:14 1072 1
593227 4738718 2011-02-11 23:10:09 1072 1
593217 4738711 2011-02-11 23:20:59 1072 1
593218 4738661 2011-02-11 23:41:31 1072 1
593198 4738690 2011-02-12 00:41:11 1072 1

For more information about targets, check out the manual (start with the Walkthrough).

2.1 Data

Data are specified in the “Data” section of the _targets.R script. The paths to all files required for the analysis are specified, then read in using the relevant function (eg. data.table::fread or sf::st_read) in the targets workflow.

# Data --------------------------------------------------------------------
# Path to fisher locs data
locs_path <- file.path('input', 'fisher.csv')

# Path to land cover, legend
lc_path <- file.path('input', 'lc.tif')
legend_path <- file.path('input', 'fisher_legend.csv')

# Path to elevation
elev_path <- file.path('input', 'elev.tif')

# Path to population density
popdens_path <- file.path('input', 'popdens.tif')

# Path to water
water_path <- file.path('input', 'water.gpkg')

2.2 Variables

Variables are specified in the “Variables” section of the _targets.R script. For example, the column names for x, y, datetime and id in the input relocation data and the resampling rate. All required variables are shown below.

# Variables ---------------------------------------------------------------
# Targets: prepare
id_col <- 'id'
datetime_col <- 't_'
x_col <- 'x_'
y_col <- 'y_'
epsg <- 32618
crs <- st_crs(epsg)
crs_sp <- CRS(crs$wkt)
tz <- 'America/New_York'

# Targets: tracks
# Split by: within which column or set of columns (eg. c(id, yr))
#  do we want to split our analysis?
split_by <- id_col

# Resampling rate
rate <- minutes(30)

# Tolerance
tolerance <- minutes(5)

# Number of random steps
n_random_steps <- 10

2.3 Troubleshooting

2.3.1 glmmTMB

There were some issues with the installing glmmTMB for Macs, here are the steps that resolved it.

  1. remove old versions of TMB, glmmTMB, and broom.mixed
  2. install xcode from app store and do all updates for my OS (takes a while)
  3. restart computer
  4. install TMB
  5. restart R
  6. install glmmTMB from source (there was a repeated warning as posted in the link but it was ok)
  7. install broom.mixed 0.2.7 using install.packages('broom.mixed')
  8. restart R

2.3.2 tidyverse

‘tidyverse’ is a meta package made up of the tidyverse packages. ‘amt’ relies heavily on the tidy packages and use their coding practices frequently. There are pros and cons to this that are discussed elsewhere. All this is to say that you may not want to install the entire ‘tidyverse’ package but just the ones necessary for your analyses. These may include ‘dplyr’, ‘tidyr’, ‘ggplot’, ‘lubridate’, etc.

2.3.3 data.table

Some issues with the compiler for Mac users. This is actually an issue for every packaged that needs a compiler. Some helpful sites to for set up: