utilMWRinput: Utility function to import data as paths or data frames

View source: R/utilMWRinput.R

utilMWRinputR Documentation

Utility function to import data as paths or data frames

Description

Utility function to import data as paths or data frames

Usage

utilMWRinput(
  res = NULL,
  acc = NULL,
  frecom = NULL,
  sit = NULL,
  wqx = NULL,
  cens = NULL,
  fset = NULL,
  runchk = TRUE,
  warn = TRUE
)

Arguments

res

character string of path to the results file or data.frame for results returned by readMWRresults

acc

character string of path to the data quality objectives file for accuracy or data.frame returned by readMWRacc

frecom

character string of path to the data quality objectives file for frequency and completeness or data.frame returned by readMWRfrecom

sit

character string of path to the site metadata file or data.frame for site metadata returned by readMWRsites

wqx

character string of path to the wqx metadata file or data.frame for wqx metadata returned by readMWRwqx

cens

character string of path to the censored data file or data.frame for censored data returned by readMWRcens

fset

optional list of inputs with elements named res, acc, frecom, sit, wqx, or cens, overrides the other arguments, see details

runchk

logical to run data checks with checkMWRresults, checkMWRacc, checkMWRfrecom, checkMWRsites, checkMWRwqx, or checkMWRcens, applies only if res, acc, frecom, sit, wqx, or cens are file paths

warn

logical to return warnings to the console (default)

Details

The function is used internally by others to import data from paths to the relevant files or as data frames returned by readMWRresults, readMWRacc, readMWRfrecom, readMWRsites, readMWRwqx, or readMWRcens. For the former, the full suite of data checks can be evaluated with runkchk = T (default) or suppressed with runchk = F.

The fset argument can used in place of the preceding arguments. The argument accepts a list with named elements as res, acc, frecom, sit, wqx, or cens, where the elements are either character strings of the path or data frames to the corresponding inputs. Missing elements will be interpreted as NULL values. This argument is provided as convenience to apply a single list as input versus separate inputs for each argument.

Any of the arguments for the data files can be NULL, used as a convenience for downstream functions that do not require all.

Value

A six element list with the imported results, data quality objective files, site metadata, wqx metadata, and censored data named "resdat", "accdat", "frecomdat", "sitdat", "wqxdat", and "censdat" respectively.

Examples

##
# using file paths

# results path
respth <- system.file('extdata/ExampleResults.xlsx', package = 'MassWateR')

# accuracy path
accpth <- system.file('extdata/ExampleDQOAccuracy.xlsx', package = 'MassWateR')

# frequency and completeness path
frecompth <- system.file('extdata/ExampleDQOFrequencyCompleteness.xlsx', 
     package = 'MassWateR')

# site path
sitpth <- system.file('extdata/ExampleSites.xlsx', package = 'MassWateR')

# wqx path
wqxpth <- system.file('extdata/ExampleWQX.xlsx', package = 'MassWateR')

# censored path
censpth <- system.file('extdata/ExampleCensored.xlsx', package = 'MassWateR')

inp <- utilMWRinput(res = respth, acc = accpth, frecom = frecompth, sit = sitpth, 
  wqx = wqxpth, cens = censpth)
inp$resdat
inp$accdat
inp$frecomdat
inp$sitdat
inp$wqxdat
inp$censdat

##
# using data frames

# results data
resdat <- readMWRresults(respth)

# accuracy data
accdat <- readMWRacc(accpth)

# frequency and completeness data
frecomdat <- readMWRfrecom(frecompth)

# site data
sitdat <- readMWRsites(sitpth)

# wqx data
wqxdat <- readMWRwqx(wqxpth)

# censored data
censdat <- readMWRcens(censpth)

inp <- utilMWRinput(res = resdat, acc = accdat, frecom = frecomdat, sit = sitdat, 
   wqx = wqxdat, cens = censdat)
inp$resdat
inp$accdat
inp$frecomdat
inp$sitdat
inp$wqxdat
inp$censdat

##
# using fset as list input

# input with paths to files
fset <- list(
  res = respth, 
  acc = accpth, 
  frecom = frecompth,
  sit = sitpth, 
  wqx = wqxpth, 
  cens = censpth
)
utilMWRinput(fset = fset)

massbays-tech/MassWateR documentation built on April 12, 2025, 7:53 p.m.