Skip to content

Commit

Permalink
Merge bcee98f into cbba0dc
Browse files Browse the repository at this point in the history
  • Loading branch information
chguiterman committed Jul 7, 2020
2 parents cbba0dc + bcee98f commit ab8d87c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
8 changes: 5 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ Suggests:
forcats,
stringr
Imports:
MASS,
stats,
ggplot2,
MASS,
plyr,
reshape2,
plyr
rlang,
stats,
tidyr
RoxygenNote: 7.0.2
Roxygen: list(markdown = TRUE)
VignetteBuilder: knitr
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,7 @@ export(series_stats)
export(write_fhx)
export(year_range)
export(yearly_recording)
importFrom(rlang,.data)
importFrom(stats,median)
importFrom(stats,quantile)
importFrom(tidyr,pivot_wider)
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ Changes in this release:
* Added spring dormant to set of rec_types. Another "noncanon" descriptor for fire scar seasonality. This aids in canonizing "D" dormant scars as the unknown year of a dormant scar (in the Northern Hemisphere)
* [Internal] Update README to Rmarkdown (.Rmd) file with `usethis::use_readme_rmd()`
* Fix typo in citation file

* Added unit tests to increase coverage and enhance error checks on future additions
* Slight change to format of FHX2 files from `write_fhx()` to include a space between the data block and years.
* Added flexibility to `read_fhx()` to handle extra space at bottom of file (present in some non-standardized FHX files available on the IMPD)
* Added DOI badge to the README


# burnr v0.5.0
Expand Down
11 changes: 9 additions & 2 deletions R/io.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ read_fhx <- function(fname, encoding, text) {
#' * "body".
#' Each referring to a portion of an FHX file that the strings are dumped into.
#'
#' @importFrom tidyr pivot_wider
#' @importFrom rlang .data
#'
#' @noRd
list_filestrings <- function(x) {
stopifnot(is_fhx(x))
Expand All @@ -157,10 +160,14 @@ list_filestrings <- function(x) {
rec_type = rep(".", length(year_range))
)
out <- rbind(out, filler)
out <- reshape2::dcast(out, year ~ series, value.var = "rec_type", fill = ".")
out <- pivot_wider(out,
names_from = .data$series,
values_from = .data$rec_type,
values_fill = list(rec_type = "."))
out <- out[order(out$year), ]
out$hackishsolution <- NULL
# Weird thing to move year to the last column of the data.frame:
out$yr <- out$year
out$yr <- paste0(" ", out$year)
out$year <- NULL
series_names <- as.character(unique(x$series))
no_series <- length(series_names)
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-io.R
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ test_that("list_filestrings() on basic FHX obj", {
)
expect_equal(target[["body"]]$a1, c(".", "[", ".", "]"))
expect_equal(target[["body"]]$b1, c("[", ".", "]", "."))
expect_equal(target[["body"]]$yr, seq(1998, 2001))
expect_equal(target[["body"]]$yr, paste0(" ", seq(1998, 2001)))
})

test_that("read_fhx() catches errors in files", {
Expand All @@ -749,6 +749,7 @@ test_that("violates_canon() warns users of new seasonality designations", {
test_that("Write a .fhx file", {
tempFile <- file.path(tempdir(), "temp.fhx")
write_fhx(TEST_FHX, tempFile)
expect_equal(readLines(tempFile), TEST_LGR2[- c(1:34)])
unlink(tempFile)
})

0 comments on commit ab8d87c

Please sign in to comment.