Skip to content

Commit

Permalink
skip header meta-data option, to bypass potential ORNL formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
khufkens committed Apr 29, 2018
1 parent 884b196 commit 1964ee1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
12 changes: 9 additions & 3 deletions R/read_daymet.r
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#'
#' @param file a Daymet Single Pixel data file
#' @param site a sitename (default = \code{NULL})
#' @param skip_header do not ingest header meta-data, logical \code{FALSE}
#' or \code{TRUE} (default = \code{FALSE})
#' @return A nested data structure including site meta-data, the full
#' header and the data as a `data.frame()`.
#' @keywords time series, Daymet
Expand All @@ -30,7 +32,8 @@
#' }

read_daymet <- function(file = NULL,
site = NULL){
site = NULL,
skip_header = FALSE){

# stop on missing files
if (is.null(file) ){
Expand Down Expand Up @@ -90,8 +93,11 @@ read_daymet <- function(file = NULL,
if (length(c(lat,lon,tile,alt)) < 4 ){
stop("Key table header elements are missing, Daymet format change?")
}

} else {
}

# if no header is detected or desired skip
# and provide fill values
if (table_cols <= 1 | skip_header) {
tile = NULL
alt = NULL
lat = NULL
Expand Down
5 changes: 4 additions & 1 deletion man/read_daymet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions tests/testthat/test_ancillary_functions.r
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ test_that("read_daymet checks of meta-data",{

# read in the Daymet file
df = try(read_daymet(paste0(tempdir(),"/Daymet_1980_1980.csv")))
df_skip_header = try(read_daymet(paste0(tempdir(),"/Daymet_1980_1980.csv"),
skip_header = TRUE))

# check read tile and coordinate info
tile = is.numeric(df$tile)
Expand Down Expand Up @@ -243,9 +245,10 @@ test_that("read_daymet checks of meta-data",{

# see if any of the runs failed
check = !inherits(df, "try-error") &
inherits(df_missing, "try-error") &
inherits(df_null, "try-error") &
null_header & tile & lat & lon & alt
!inherits(df_skip_header, "try-error") &
inherits(df_missing, "try-error") &
inherits(df_null, "try-error") &
null_header & tile & lat & lon & alt

# check if no error occured
expect_true(check)
Expand Down

0 comments on commit 1964ee1

Please sign in to comment.