```{asis, echo = {{envs_ecoclimate_knit}}, eval = {{envs_ecoclimate_knit}}, include = {{envs_ecoclimate_knit}}}

Obtain environmental data

Using Ecoclimate (http://www.ecoclimate.org) dataset at resolution of 0.5 degrees.

```r}, include = {{envs_ecoclimate_knit}}}
# R code to get environmental data from Ecoclimate
envs_{{spAbr}} <- envs_ecoClimate(
  bcAOGCM = "{{bcAOGCM_rmd}}",
  bcScenario = "{{bcScenario_rmd}}",
  ecoClimSel = {{ecoClimSel_rmd}}) 
##Add envrionmental values to occurrences table
occs_xy_{{spAbr}} <- occs_{{spAbr}}[c('longitude', 'latitude')]
occs_vals_{{spAbr}} <- as.data.frame(raster::extract(envs_{{spAbr}}, occs_xy_{{spAbr}}, cellnumbers = TRUE))
# Remove duplicated same cell values
occs_{{spAbr}} <- occs_{{spAbr}}[!duplicated(occs_vals_{{spAbr}}[, 1]), ]
occs_vals_{{spAbr}} <- occs_vals_{{spAbr}}[!duplicated(occs_vals_{{spAbr}}[, 1]), -1]
# remove occurrence records with NA environmental values
occs_{{spAbr}} <- occs_{{spAbr}}[!(rowSums(is.na(occs_vals_{{spAbr}})) >= 1), ]
# also remove variable value rows with NA environmental values
occs_vals_{{spAbr}} <- na.omit(occs_vals_{{spAbr}})
# add columns for env variable values for each occurrence record
occs_{{spAbr}} <- cbind(occs_{{spAbr}}, occs_vals_{{spAbr}})


Try the wallace package in your browser

Any scripts or data that you put into this service are public.

wallace documentation built on Sept. 11, 2024, 9:16 p.m.