4 Using R

The neotoma2 R package provides a set of functions to download and work with data from Neotoma within the R programming environment. The package has been designed for users who wish to work with multiple sites or datasets, and supports users who wish to add their own data into Neotoma.

The functions in the R package act as wrappers for the API calls, and also provide some secondary services to help the data work efficiently in the R environment. For example, a user who wishes to search for all sites named ‘Marion Lake’ using R simply uses the get_sites() function:

library(neotoma2)
## The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
## which was just loaded, will retire in October 2023.
## Please refer to R-spatial evolution reports for details, especially
## https://r-spatial.org/r/2023/05/15/evolution4.html.
## It may be desirable to make the sf package available;
## package maintainers should consider adding sf to Suggests:.
## The sp package is now running under evolution status 2
##      (status 2 uses the sf package in place of rgdal)
## 
## Attaching package: 'neotoma2'
## The following object is masked from 'package:jsonlite':
## 
##     toJSON
## The following object is masked from 'package:stats':
## 
##     filter
marion <- get_sites(sitename = "Marion Lake")
marion
##  siteid    sitename      lat      long altitude
##    1649 Marion Lake 49.30833 -122.5472      305
##   13416 Marion Lake 44.55609 -121.8648     1259

The following sections will detail several workflows using the R package. To help the end user we have created an instance of RStudio that is available from the browser, with all packages installed. You can access this version of RStudio from the myBinder link:

Binder

While many of our examples are drawn directly from existing workshop materials, you may find more complete details about using the R package on the GitHub page for the package, or in one or more of our posted workshops:

Other workshop materials are available within the Neotoma Workshops GitHub repository. Some workshops are highly specialized, and some contain links to cloud-based versions of RStudio so that users can work on the problems and workflows under standardized conditions.