Skip to content

ny/dow-sentry-package

Repository files navigation

Sentry

The goal of Sentry is to aid in extracting, transforming, and loading (ETL) laboratory data provided to the bureau of water assessment and management (BWAM).

Installation

You can install the development version of Sentry from GitHub with:

# install.packages("devtools")
devtools::install_github("BWAM/sentry")

Example

Load the R package.

library(Sentry)

Define the output directory. Here I am just creating a temporary directory to store the output.

(output_dir <- tempdir())
#> [1] "C:\\Users\\zmsmith.000\\AppData\\Local\\Temp\\Rtmpm63aAn"

Single Zip File

Extract and transform ALS Rochester data.

dat <- read_als(zip_path = here::here("inst",
                                      "example_zips",
                                      "R2004299.zip"))

Export the ALS data as a JSON object.

export_json(
  x = dat,
  path = output_dir,
  filename = "r2004299"
)

Multiple Zip Files

Create a vector that contains the file paths of all of the data files of interest.

file_vec <- list.files(
  path = here::here("inst",
                    "example_zips"),
  pattern = "zip",
  full.names = TRUE,
  include.dirs = TRUE
)

Name the vector elements based on the base file name.

names(file_vec) <- gsub(pattern = "\\.zip",
                        replacement = "",
                        x = basename(file_vec))

This for loop iterates over the vector of files created above (file_vec) importing, transforming, and exporting data as a JSON object.

for (i in seq_along(file_vec)) {
   dat <- read_als(zip_path = file_vec[i])
  
  export_json(x = dat,
              path = output_dir,
              filename = names(file_vec[i]))
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published