This project exports a single R6 class for the R programming language that can be used to make HTTP requests to the Hakai API resource server. The Class provides a “get” method to make Authenticated requests to the Hakai API data server without needing to know the details of the authentication process.
Before using this library, install it into your environment using one of the following in your R script:
# From CRAN
install.packages("hakaiApi")
# OR, the latest version from GitHub
install.packages("remotes")
::install_github("HakaiInstitute/hakai-api-client-r", subdir='hakaiApi') remotes
# Initialize the client
<- hakaiApi::Client$new()
client
# Request some data (request chlorophyll data here)
<- client$get("https://hecate.hakai.org/api/eims/views/output/chlorophyll?limit=50")
data
# View out the data
View(data)
This library exports a single class named Client
.
Instantiating this class with the $new
method sets up the
credentials for requests using the $get
method.
The hakai_api Client
class also contains a property
api_root
which is useful for constructing urls to access
data from the API. The above Quickstart
example demonstrates using this property to construct a url to
access chlorophyll data.
If for some reason your credentials become corrupted and stop
working, there is a method to remove the old cached credentials for your
account so you can re-authenticate. just do
client$remove_old_credentials()
.
For details about the API, including available endpoints where data can be requested, see the Hakai API documentation.
You can specify which API to access when instantiating the Client. By
default, the API uses https://hecate.hakai.org/api
as the
API root. It may be useful to use this library to access a locally
running API instance or to access the Goose API for testing
purposes.
# Get a client for a locally running API instance
<- hakaiApi::Client$new("localhost:8666")
client print(client$api_root) # http://localhost:8666
This class defines a number of public and private variables and methods that make this request client work. The development of this class was largely informed by the R project’s R6 class documentation. To build this class into a R package, this tutorial was followed.
Sam Albers (sam.albers@hakai.org) Taylor Denouden (taylor.denouden@hakai.org)
Copyright (c) 2025 Hakai Institute and individual contributors All Rights Reserved.