```{asis, echo = {{penvs_userBgExtent_knit}}, eval = {{penvs_userBgExtent_knit}}, include = {{penvs_userBgExtent_knit}}}
### Process environmental data
Sampling of {{bgPtsNum_rmd}} background points and corresponding environmental data using a user provided background extent with a {{userBgBuf_rmd}} degree buffer.
```

```{r, echo = {{penvs_userBgExtent_knit}}, include = {{penvs_userBgExtent_knit}}}
# Load the user provided shapefile or csv file with the desired extent.
  ##User must input the path to shapefile or csv file and the file name 
# Define path
bgPath_{{spAbr}} <- ""
bgExt_{{spAbr}} <- penvs_userBgExtent(
  bgShp_path = paste0(bgPath_{{spAbr}}, "{{bgShp_name_rmd}}", ".shp"),
  bgShp_name = paste0("{{bgShp_name_rmd}}", c(".shp", ".shx", ".dbf")),
  userBgBuf = {{userBgBuf_rmd}},
  occs = occs_{{spAbr}})
# Mask environmental data to provided extent
bgMask_{{spAbr}} <- penvs_bgMask(
  occs = occs_{{spAbr}},
  envs = envs_{{spAbr}},
  bgExt = bgExt_{{spAbr}})
# Sample background points from the provided area
bgSample_{{spAbr}} <- penvs_bgSample(
  occs = occs_{{spAbr}},
  bgMask =  bgMask_{{spAbr}},
  bgPtsNum = {{bgPtsNum_rmd}})
# Extract values of environmental layers for each background point
bgEnvsVals_{{spAbr}} <- as.data.frame(raster::extract(bgMask_{{spAbr}},  bgSample_{{spAbr}}))
##Add extracted values to background points table
bgEnvsVals_{{spAbr}} <- cbind(scientific_name = paste0("bg_", "{{spName}}"), bgSample_{{spAbr}},
                            occID = NA, year = NA, institution_code = NA, country = NA,
                            state_province = NA, locality = NA, elevation = NA,
                            record_type = NA, bgEnvsVals_{{spAbr}})
```
