Introduction

One of the greatest spatial analysis packages in R called raster has seen great growth in development of spatially sensitive packages such as sdm since its inception in 2010. However, maintenance of the package is likely to be halted in 2023 among other platforms like maptools, sp, rgeos, and rgdal. As a response,other spatial analysis packages have come to the surface such as sf, terra, and stars. At its present version (1.1.8), the model building process of the package does not support the incoming packages but still run on the older retiring packages. There is therefore need to shift the capabilities of sdm package, of course and many other packages depending on the older platforms, to embrace the new file structures produced by the new ‘tidy’ packages. The new platforms are praised for being able to do more, easier to use, and faster see. It is in this light that I draft this short post.

Check my GitHub for code files.

Loading data

Loading species occurrence data

Using st_read() function from sf package, we can easily load spatial vector data into R in a tidy kind of spatial data that can be easily wrangled by other tidyverse packages. Here I load in species occurrence data that comes with the sdm pakage.

file <- system.file("external/species.shp", package = "sdm")
species <- st_read(file) # Note, instead of shapefile(file) I use st_read(file)
## Reading layer `species' from data source 
##   `D:\R2\R-4.1.2\library\sdm\external\species.shp' using driver `ESRI Shapefile'
## Simple feature collection with 200 features and 1 field
## Geometry type: POINT
## Dimension:     XY
## Bounding box:  xmin: 110112 ymin: 4013700 xmax: 606053 ymax: 4275600
## Projected CRS: WGS 84 / UTM zone 30N

Loading raster data

Here, I read in raster predictor variables using read_stars() from stars package.

path <- system.file("external", package = "sdm")
lst <- list.files(path = path, pattern = 'asc$', full.names = T)
preds <- read_stars(lst) # Instead of stack() from raster, I use read_stars() from stars package.

Multicollinearity check

Here I use st_extract() function from sf to obtain pixel values corresponding to occurrence points. Note vifcor(), at its present version (1.1.18), does not support stars objects from stars package and SpatRaster or terra from terra package. This, accordingly, also needs improvement.

st_crs(preds) <- st_crs(species)
extract <- st_extract(preds, species)
v <- vifcor(data.frame(elevation = extract$elevation.asc, 
                       precipitation = extract$precipitation.asc,
                       temperature = extract$temperature.asc, 
                       vegetation = extract$vegetation.asc))

The Barrier

It is however, still not possible to use the sf and stars objects above directly in sdmData() function, meaning no sdm model can be built upon them.

# d <- sdmData(formula=Occurrence~., train=species, predictors=preds)

The call

It is therefore my humble call, and I hope the larger sdm community would agree, that future versions of sdm and usdm packages should consider accommodating outputs from modern packages such as sf, stars, and terra that we use to prepare data just before building and running the model. The sdm community is also concerned with an issue while generating output gui with latest version of shiny package (I have not detailed that here).

Personally, I am not a developer but rather a user and I think identifying such looming problems could help developers work around them in time for seamless transition.

Best regards and enjoy the holidays.

References

Allaire, JJ, Yihui Xie, Jonathan McPherson, Javier Luraschi, Kevin Ushey, Aron Atkins, Hadley Wickham, Joe Cheng, Winston Chang, and Richard Iannone. 2021. Rmarkdown: Dynamic Documents for r. https://CRAN.R-project.org/package=rmarkdown.
Bivand, Roger S., Edzer Pebesma, and Virgilio Gomez-Rubio. 2013. Applied Spatial Data Analysis with R, Second Edition. Springer, NY. https://asdar-book.org/.
Henry, Lionel, and Hadley Wickham. 2020. Purrr: Functional Programming Tools. https://CRAN.R-project.org/package=purrr.
Hijmans, Robert J. 2021a. Raster: Geographic Data Analysis and Modeling. https://rspatial.org/raster.
———. 2021b. Terra: Spatial Data Analysis. https://rspatial.org/terra/.
Müller, Kirill, and Hadley Wickham. 2021. Tibble: Simple Data Frames. https://CRAN.R-project.org/package=tibble.
Naimi, Babak. 2017. Usdm: Uncertainty Analysis for Species Distribution Models. http://r-gis.net.
Naimi, Babak, and Miguel B. Araujo. 2016. “Sdm: A Reproducible and Extensible r Platform for Species Distribution Modelling.” Ecography 39: 368–75. https://doi.org/10.1111/ecog.01881.
———. 2021. Sdm: Species Distribution Modelling. https://www.biogeoinformatics.org.
Naimi, Babak, Nicholas a.s. Hamm, Thomas A. Groen, Andrew K. Skidmore, and Albertus G. Toxopeus. 2014. “Where Is Positional Uncertainty a Problem for Species Distribution Modelling.” Ecography 37: 191–203. https://doi.org/10.1111/j.1600-0587.2013.00205.x.
Pebesma, Edzer. 2018. Simple Features for R: Standardized Support for Spatial Vector Data.” The R Journal 10 (1): 439–46. https://doi.org/10.32614/RJ-2018-009.
———. 2021a. Sf: Simple Features for r. https://CRAN.R-project.org/package=sf.
———. 2021b. Stars: Spatiotemporal Arrays, Raster and Vector Data Cubes. https://CRAN.R-project.org/package=stars.
Pebesma, Edzer J., and Roger S. Bivand. 2005. “Classes and Methods for Spatial Data in R.” R News 5 (2): 9–13. https://CRAN.R-project.org/doc/Rnews/.
Pebesma, Edzer, and Roger Bivand. 2021. Sp: Classes and Methods for Spatial Data. https://CRAN.R-project.org/package=sp.
Plate, Tony, and Richard Heiberger. 2016. Abind: Combine Multidimensional Arrays. https://CRAN.R-project.org/package=abind.
R Core Team. 2021. R: A Language and Environment for Statistical Computing. Vienna, Austria: R Foundation for Statistical Computing. https://www.R-project.org/.
Wickham, Hadley. 2016. Ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York. https://ggplot2.tidyverse.org.
———. 2019. Stringr: Simple, Consistent Wrappers for Common String Operations. https://CRAN.R-project.org/package=stringr.
———. 2021a. Forcats: Tools for Working with Categorical Variables (Factors). https://CRAN.R-project.org/package=forcats.
———. 2021b. Tidyr: Tidy Messy Data. https://CRAN.R-project.org/package=tidyr.
———. 2021c. Tidyverse: Easily Install and Load the Tidyverse. https://CRAN.R-project.org/package=tidyverse.
Wickham, Hadley, Mara Averick, Jennifer Bryan, Winston Chang, Lucy D’Agostino McGowan, Romain François, Garrett Grolemund, et al. 2019. “Welcome to the tidyverse.” Journal of Open Source Software 4 (43): 1686. https://doi.org/10.21105/joss.01686.
Wickham, Hadley, Winston Chang, Lionel Henry, Thomas Lin Pedersen, Kohske Takahashi, Claus Wilke, Kara Woo, Hiroaki Yutani, and Dewey Dunnington. 2021. Ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics. https://CRAN.R-project.org/package=ggplot2.
Wickham, Hadley, Romain François, Lionel Henry, and Kirill Müller. 2021. Dplyr: A Grammar of Data Manipulation. https://CRAN.R-project.org/package=dplyr.
Wickham, Hadley, Jim Hester, and Jennifer Bryan. 2021. Readr: Read Rectangular Text Data. https://CRAN.R-project.org/package=readr.
Xie, Yihui. 2014. “Knitr: A Comprehensive Tool for Reproducible Research in R.” In Implementing Reproducible Computational Research, edited by Victoria Stodden, Friedrich Leisch, and Roger D. Peng. Chapman; Hall/CRC. http://www.crcpress.com/product/isbn/9781466561595.
———. 2015. Dynamic Documents with R and Knitr. 2nd ed. Boca Raton, Florida: Chapman; Hall/CRC. https://yihui.org/knitr/.
———. 2021. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.
Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.
Xie, Yihui, Christophe Dervieux, and Emily Riederer. 2020. R Markdown Cookbook. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown-cookbook.