/
readMWRresults.R
35 lines (30 loc) · 1.29 KB
/
readMWRresults.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#' Read water quality monitoring results from an external file
#'
#' @param respth character string of path to the results file
#' @param runchk logical to run data checks with \code{\link{checkMWRresults}}
#' @param warn logical to return warnings to the console (default)
#' @param tzone character string for time zone, passed to \code{\link{formMWRresults}}
#'
#' @return A formatted water quality monitoring results data frame that can be used for downstream analysis
#'
#' @details Date are imported with \code{\link[readxl]{read_excel}}, checked with \code{\link{checkMWRresults}}, and formatted with \code{\link{formMWRresults}}.
#'
#' @export
#'
#' @seealso \code{\link{readMWRresultsview}} for troubleshooting import checks
#'
#' @examples
#' respth <- system.file('extdata/ExampleResults.xlsx', package = 'MassWateR')
#'
#' resdat <- readMWRresults(respth)
#' head(resdat)
readMWRresults <- function(respth, runchk = TRUE, warn = TRUE, tzone = 'America/Jamaica'){
resdat <- suppressWarnings(readxl::read_excel(respth, na = c('NA', 'na', ''), guess_max = Inf)) %>%
dplyr::mutate_if(function(x) !lubridate::is.POSIXct(x), as.character)
# run checks
if(runchk)
resdat <- checkMWRresults(resdat, warn = warn)
# format results
out <- formMWRresults(resdat, tzone)
return(out)
}