hawkinR
An R interface to the Hawkin Dynamics API. Simple authentication, region-aware routing, and tidy data frames for sport scientists and analysts.
Installation
Install hawkinR from GitHub using devtools.
Authentication
hawkinR uses a simple authentication flow. Set your refresh token as an environment variable and connect.
Set Your Environment Variable
Set HD_REFRESH_TOKEN in your .Renviron file. Run usethis::edit_r_environ() to open it.
Connect to the API
Use get_access(region = "Americas") to authenticate. This exchanges your refresh token for an access token automatically.
Start Querying
All get_*() functions use the active session automatically. No token management needed.
Quick Start
A complete, runnable script to get your first data.
Regional Endpoints
Set the region parameter in get_access() to match your organization's data residency.
| Region | Value | Base URL |
|---|---|---|
| Americas | "Americas" |
cloud.hawkindynamics.com |
| Europe | "Europe" |
eu.cloud.hawkindynamics.com |
| Asia-Pacific | "APAC" |
apac.cloud.hawkindynamics.com |
User Guide
In-depth tutorials covering authentication, data retrieval, force-time analysis, logging, and integrating hawkinR into web applications.
Getting Started with hawkinR
hawkinR manages the exchange of your Integration Key (Refresh Token) for an ephemeral Access Token automatically in the background.
Setting Up Your Token
Store your refresh token as an environment variable in your .Renviron file. This keeps your key out of your scripts and available across sessions.
Connecting to the Cloud
Use get_access() to initialize your session. This exchanges your refresh token for an access token automatically.
Exploring Your Organization
Once connected, retrieve the structural data of your organization. These IDs are used as filters when pulling performance tests.
Authentication Deep Dive
hawkinR provides flexible authentication options for different deployment scenarios.
Environment Variable (Recommended)
Set your refresh token as an environment variable for persistent, secure access across sessions.
Direct Token
Pass your refresh token directly for quick testing or one-off scripts.
Cloud Deployment
When deploying to a server (ShinyApps.io, Posit Connect, Docker), set the HD_REFRESH_TOKEN environment variable on your hosting platform.
| Function | Purpose |
|---|---|
get_access(region) | Authenticates and initializes the active session |
get_tests(...) | Fetches data using the current active session |
Getting Tests
The get_tests() function is the primary tool for querying performance data. This function provides unified access to test data with flexible filtering.
get_tests_ath(), get_tests_team(), get_tests_group(), and get_tests_type() are deprecated. Use get_tests() with filter parameters instead.
Basic Usage
Provide a date range using standard date strings or Unix timestamps.
Filter by Test Type
Use canonical ID, test type name, or abbreviation.
Filter by Athletes, Teams, or Groups
teamId and groupId in the same call.
The Sync Parameter
For incremental refresh logic, use sync = TRUE to pull data based on when it was uploaded/modified rather than when the test occurred.
Data Structure
The returned data frame is organized into four logical sections:
| Section | Contents |
|---|---|
| Trial Info | Basic trial metadata (ID, timestamp) |
| Test Type Info | Details about the movement performed |
| Athlete Info | Athlete details (name, teams, groups, external) |
| Metrics | All performance metrics (Force, Velocity, Power, etc.) |
Including Inactive Data
By default, only "Active" trials are returned. For auditing, set includeInactive = TRUE.
Accessing Force-Time Data
Use get_forcetime() to access the high-frequency raw data (1000Hz) from test trials.
Fetching a Single Test
Get the unique id from get_tests(), then fetch the raw data.
Plotting
Logging Features
hawkinR uses the logger package to provide status changes, background processes, and debugging information. Logging is initialized automatically when you call get_access().
Log Levels
Use initialize_logger() to configure logging:
| Level | Use Case |
|---|---|
TRACE | Detailed execution logs including request paths |
DEBUG | Information useful for debugging |
INFO | (Default) Standard process updates |
WARN | Warnings about token expiration or non-critical issues |
ERROR | Critical failures only |
Verbose Debugging
Silent Operation (Production)
Logging to Files
Integrating hawkinR with Web Applications
hawkinR integrates easily with Shiny apps, Plumber APIs, and containerized environments.
Shiny
Use get_access() with the HD_REFRESH_TOKEN environment variable configured on your hosting platform (ShinyApps.io, Posit Connect).
HD_REFRESH_TOKEN environment variable in your app's Settings → Environment Variables panel. On Posit Connect, use the "Vars" tab in the content settings.
Plumber API
Serve Hawkin data as REST endpoints. Connect on startup, let Plumber handle requests.
Docker
Pass the token as an environment variable when running the container.
Function Reference
Complete documentation for all public hawkinR functions — signatures, parameters, return values, and examples.
get_access(refreshToken, region, org_name)
Authenticates with the Hawkin Dynamics API by exchanging your refresh token for an access token. Sets the active session for subsequent data calls.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
refreshToken | character | NULL | Your API refresh token. If NULL, reads from HD_REFRESH_TOKEN environment variable |
region | character | "Americas" | API region: "Americas", "Europe", or "APAC" |
org_name | character | NULL | Optional organization name for display |
Returns
Invisibly returns the access token. Sets the active session for use by all get_*() functions.
Example
get_tests(from, to, sync, athleteId, typeId, teamId, groupId, includeInactive)
Retrieves test data from the Hawkin Dynamics API. Supports filtering by athlete, team, group, test type, and date range.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
from | int / chr | NULL | Start time. Unix timestamp or "YYYY-MM-DD" |
to | int / chr | NULL | End time. Unix timestamp or "YYYY-MM-DD". Defaults to now |
sync | logical | FALSE | If TRUE, includes updated and newly created tests |
athleteId | character | NULL | Filter by specific athlete ID |
typeId | character | NULL | Filter by test type (canonical ID, name, or abbreviation) |
teamId | chr / list | NULL | Filter by team ID(s). Max 10 |
groupId | chr / list | NULL | Filter by group ID(s). Max 10 |
includeInactive | logical | FALSE | Include inactive tests |
Returns
Data frame containing test trials and their metrics. Each row represents a single test trial.
Examples
get_forcetime(testId)
Retrieves the raw force-time data for a specific test trial ID. Returns time-series arrays sampled at 1000 Hz.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
testId | character | — | The unique identifier for the test trial |
Returns
A HawkinForceTime object containing force-time series data.
get_metrics(testType)
Get all metrics and their IDs. Can be filtered by test type using canonical ID, name, or abbreviation (e.g., "CMJ", "SJ", "ISO", "DJ").
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
testType | character | "all" | Canonical test ID, test type name, or abbreviation |
Returns
Data frame with columns: canonicalTestTypeID, testTypeName, id, label, label_unit, header, units, description.
Example
get_athletes(includeInactive)
Get all athletes for an account. Inactive athletes only included if includeInactive is TRUE.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
includeInactive | logical | FALSE | Include inactive athletes |
Returns
Data frame with columns: id, name, active, teams, groups, external properties.
Example
get_teams()
Get team names and IDs for all teams in the organization.
Returns
Data frame with columns: id, name.
Example
get_groups()
Get group names and IDs for all groups in the organization.
Returns
Data frame with columns: id, name.
Example
get_tags()
Get tag names and IDs for all tags in the system.
Returns
Data frame with columns: id, name, description.
Example
create_athletes(athleteData)
Create new athletes for an account. Bulk create up to 500 athletes at a time.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
athleteData | data.frame | — | Athletes to create. Required column: name. Optional: image, active, teams, groups, plus any external property columns |
Returns
Prints confirmation with count of created athletes. If failures, returns data frame with reason and name columns.
Example
update_athletes(athleteData)
Update existing athletes. Bulk update up to 500 at a time. Optional fields not present are left unchanged, but external properties not included will be removed.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
athleteData | data.frame | — | Athletes to update. Required column: id. Optional: name, image, active, teams, groups, external properties |
external properties, any custom properties not present in the request will be removed. Always include all external properties you want to keep.
initialize_logger(log_output, log_threshold_stdout, log_file, log_threshold_file)
Initialize the logger with custom output destination and log thresholds for stdout and file.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
log_output | character | "stdout" | "stdout", "file", or "both" |
log_threshold_stdout | character | "INFO" | "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL" |
log_file | character | "hawkinRlog.log" | Custom log file name/path |
log_threshold_file | character | "INFO" | Log threshold for the file output |
Example
Changelog
Release notes and version history for hawkinR.
Unified get_tests, logging, bug fixes
- Updated
get_tests()with unified filtering - Deprecated
get_tests_*functions teamIdandgroupIdnow accept lists and vectors- Added logging functionality and customization
- TruStrength test types support
- Various bug fixes for tags, date formatting
Initial release
- Core functions:
get_tests_*,get_athletes,get_teams,get_groups,get_forcetime - Added
get_tags(),typeIdabbreviations - Tag details in test outputs
- External ID and sync support