Learn R Programming

MazamaCoreUtils

MazamaCoreUtils is a suite of utility functions for production-level R code, providing functionality commonly needed by operational systems such as logging, error handling, cache management and date-time parsing.

Functions for date-time parsing and formatting require that time zones be specified explicitly, avoiding a common source of error when working with environmental time series.

Installation

Install the released version from CRAN:

install.packages("MazamaCoreUtils")

Install the development version from GitHub:

remotes::install_github("MazamaScience/MazamaCoreUtils")

MazamaCoreUtils requires R version 4.0.0 or later.

Example

Set up standard log files, request a range of days in an explicit time zone and record the request in the log:

library(MazamaCoreUtils)

# Create TRACE, DEBUG, INFO, WARN and ERROR log files
logDir <- file.path(tempdir(), "logs")
initializeLogging(logDir)

# Date-times always require an explicit time zone
tlim <- dateRange("2024-03-01", "2024-03-03", timezone = "America/Los_Angeles")
tlim
#> [1] "2024-03-01 00:00:00 PST" "2024-03-02 23:59:59 PST"

logger.info(
  "Requesting data from %s to %s",
  timeStamp(tlim[1], timezone = "America/Los_Angeles", unit = "min", style = "clock"),
  timeStamp(tlim[2], timezone = "America/Los_Angeles", unit = "min", style = "clock")
)

readLines(file.path(logDir, "INFO.log"))

Overview

  • Logging — initializeLogging(), logger.setup(), logger.setLevel(), logger.info(), logger.error()
  • Error handling and NULL values — stopOnError(), stopIfNull(), setIfNull()
  • Date-times with explicit time zones — parseDatetime(), dateRange(), timeRange(), dateSequence(), timeStamp()
  • Locations — validateLonLat(), createLocationMask(), createLocationID()
  • Cache management and data loading — manageCache(), loadDataFile()
  • API keys — setAPIKey(), getAPIKey(), showAPIKeys()
  • HTML utilities — html_getLinks(), html_getTables()
  • Code linting and package checks — lintFunctionArgs_file(), timezoneLintRules, check_fast()

Detailed argument and return value documentation is available in the function help pages, for example ?parseDatetime.

Background

MazamaCoreUtils was created by Mazama Science to standardize the work of building R packages, data processing pipelines and web services focused on environmental monitoring data. Its functions are used by other Mazama Science packages and by systems that are run operationally, where consistent logging, clear error messages and unambiguous time zones matter.

Documentation and Help

  • CRAN package page for the reference manual and vignettes on cache management, date parsing, error handling and logging
  • GitHub Issues for bug reports
  • GitHub Discussions for announcements, support and building a community of practice around this package

Questions regarding further development of the package can also be directed to [email protected].

Citation

For citation information, use:

citation("MazamaCoreUtils")

Acknowledgements

Development of this package has been supported with funding from the USFS AirFire Research Team.

License

MazamaCoreUtils is released under the GPL-3 license.

Copy Link

Version

Install

install.packages('MazamaCoreUtils')

Monthly Downloads

531

Version

0.6.3

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Jonathan Callahan

Last Published

September 30th, 2026

Functions in MazamaCoreUtils (0.6.3)

logLevels

Log levels
lintFunctionArgs

Lint function calls for required named arguments
logger.debug

Python-style logging statements
logger.fatal

Python-style logging statements
logger.isInitialized

Check whether logging has been initialized
logger.setup

Set up Python-style logging
logger.trace

Python-style logging statements
packageCheck

Run package checks
manageCache

Manage cache size
stopIfNull

Stop if an object is NULL
showAPIKeys

Show API keys
parseDatetime

Parse datetimes
logger.warn

Python-style logging statements
%>%

Pipe operator
setAPIKey

Set API key
timeRange

Create a POSIXct time range
timeStamp

Create character timestamps
stopOnError

Stop on try-error
timezoneLintRules

Timezone linting rules
validateLonLat

Validate longitude and latitude values
tidyeval-data

Data pronoun for tidy evaluation
setIfNull

Set a variable to a default value if it is NULL
validateLonsLats

Validate longitude and latitude vectors
initializeLogging

Initialize standard log files
getAPIKey

Get API key
createLocationMask

Create a mask of valid locations
html_getTables

Extract tables from an HTML page
dateSequence

Create a POSIXct date sequence
dateRange

Create a POSIXct date range
html_getLinks

Extract links from an HTML page
createLocationID

Create one or more unique location IDs
logger.error

Python-style logging statements
logger.info

Python-style logging statements
logger.setLevel

Set console log level
MazamaCoreUtils-package

MazamaCoreUtils
APIKeys

API keys for data services
loadDataFile

Load R data from a URL or local file