Skip to content

Commit

Permalink
Fixed FHX2 FORMAT string bug in read_fhx()
Browse files Browse the repository at this point in the history
  • Loading branch information
brews committed Feb 7, 2017
1 parent 4bee3f0 commit 933f6e3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Changes in this minor release:

* Fixed additional bug in `read_fhx()` caused by "FHX2 format" in FHX file header.

* Fixed bug #71, causing `read_fhx()` to fail when FHX has empty lastline.

* Added `text` option to `read_fhx()`.
Expand Down
4 changes: 2 additions & 2 deletions R/io.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ read_fhx <- function(fname, encoding, text) {
if (length(readLines(con, n = 1)) == 0)
stop("file appears to be empty")
fl <- readLines(con, warn = FALSE)
if (!any(suppressWarnings(grepl("FHX2 FORMAT|FIRE2 FORMAT", fl, ignore.case = TRUE))))
if (!any(suppressWarnings(grepl("^FHX2 FORMAT|^FIRE2 FORMAT", fl, ignore.case = TRUE))))
stop("Cannot find line 'FHX2 FORMAT' or 'FIRE2 FORMAT'.")
first <- suppressWarnings(grep("FHX2 FORMAT|FIRE2 FORMAT", fl, ignore.case = TRUE))
first <- suppressWarnings(grep("^FHX2 FORMAT|^FIRE2 FORMAT", fl, ignore.case = TRUE))
describe <- as.numeric(strsplit(fl[[first + 1]], " ")[[1]])
if (length(describe) != 3) { # First year; no. sites; length of site id.
stop(paste("Three-digit descriptive information that should be on line ",
Expand Down

0 comments on commit 933f6e3

Please sign in to comment.