top of page
NABat Coordination Team

Getting started with the NABat R package:

The NABat R package can be used to extract and summarize data from NABat projects and data requests. This package includes functions that can reformat NABat data, create reports, find GRTS cells, and more. The NABat R package repository is located at https://code.usgs.gov/fort/nabat/nabatr. Please note that a previous version used a github.com page, but that repository has been deprecated in favor of the code.usgs.gov page.  

 

1. Before using the NABat R package, download R and Rtools. Information on how to download and install these can be found here: 

The R package “devtools” is also required to load the NABat R package 

 

For users who have not already done so, it is recommended to create an NABat account. An account is not required to download the R package. However, since access to data is determined by NABat project permissions and/or previously approved data requests, most of the functionality of the NABat R package depends on having an NABat account. For information on how to set up an account, please see: https://www.nabatmonitoring.org/create-an-account 

 

2. To install the NABat R package, either install from a reference version of a software release: 

 

devtools::install_git("https://code.usgs.gov/fort/nabat/nabatr.git", ref = "v1.0.1") 

 

Or install the provisional software (which will be most up-to-date): 

 

 

Then, call the package using the “library” function: 

 

library(nabatr) 

 

Another option is to download the source code directly from the repository, then load the package from directly from your desktop: 

 

devtools::load_all("insert path to source code here") 

 

3. After downloading the package, a token is required to access any data. This token can be obtained in two ways. If logged into the NABat partner portal (https://sciencebase.usgs.gov/nabat), click the “API” button in the upper righthand corner, which will generate a pop-up window with a code snippet. Paste that snippet into an R script, while also setting the username as the email associated with an NABat account: 

 

username = 'user email' 

token = 'paste remaining code snipped here' 

 

Alternatively, enter the username, then use the get_nabat_gql_token function, which will generate a pop-up where an NABat account password can be entered: 

 

username = 'NABat_Username' 

token = get_nabat_gql_token(username) 

 

Tokens need to be occasionally refreshed: 

 

token = get_refresh_token(token) 

 

Tokens may expire after about an hour, which requires logging in again (either using the code snippet from the partner portal page or by re-entering your password).   

 

4. To further explore the functionalities of the NABat R package, several vignettes are available and can be accessed using: 

 

browseVignettes(“nabatr”) or vignette(package = “nabatr”) 

 

These vignettes can also be viewed on the NABat R package repository page.  

 

For questions or assistance with the NABat R package, please feel free to reach out to the NABat team: https://www.nabatmonitoring.org/our-team 

 

149 views

Recent Posts

See All

Comments


bottom of page