Skip to content

Commit

Permalink
suppress scientific notation in legacyids, closes #96
Browse files Browse the repository at this point in the history
  • Loading branch information
jsta committed Jan 31, 2019
1 parent 7ff004f commit 0d16db9
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion R/compile.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#'@export
#'
#'@examples \dontrun{
#' lagosne_compile("1.087.1"
#' lagosne_compile("1.087.1",
#' limno_folder = "~/Downloads/LAGOS-NE-LIMNO-EXPORT",
#' geo_folder = "~/Downloads/LAGOS-NE-GEO-EXPORT",
#' locus_folder = "~/Downloads/LAGOS-NE-LOCUS-EXPORT")
Expand Down
5 changes: 4 additions & 1 deletion R/ingest.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#'@importFrom utils read.table
#'@importFrom progress progress_bar
#'@examples \dontrun{
#' lagosne_ingest("1.087.1",
#' lagos_ingest("1.087.1",
#' limno_folder = "~/Downloads/LAGOS-NE-LIMNO-EXPORT",
#' geo_folder = "~/Downloads/LAGOS-NE-GEO-EXPORT",
#' locus_folder = "~/Downloads/LAGOS-NE-LOCUS-EXPORT")
Expand Down Expand Up @@ -50,6 +50,9 @@ lagos_ingest <- function(version, limno_folder = NA, geo_folder = NA,

lakes_limno <- load_lagos_txt(limno_path("lakeslimno"),
sep = ",")
lakes_limno$legacyid <-
suppressWarnings(sapply(lakes_limno$legacyid, format_nonscientific))

secchi <- load_lagos_txt(limno_path("secchi"),
sep = ",")
lagos_source_program <- load_lagos_txt(limno_path("sourceprogram"),
Expand Down
12 changes: 11 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ load_lagos_txt <- function(file_name, sep = "\t", ...){
read.table(file_name, header = TRUE, sep = sep, quote = "\"",
dec = ".", strip.white = TRUE, comment.char = "",
stringsAsFactors = FALSE)

}

#' Summarize all LAGOSNE flat files
Expand Down Expand Up @@ -253,3 +252,14 @@ pad_huc_ids <- function(dt, col_name, len){
dt[,col_name] <- as.character(res)
dt
}

format_nonscientific <- function(x){
if(is.na(as.numeric(x))){
x
}else{
trimws(
format(
as.numeric(x), scientific = FALSE, drop0trailing = TRUE)
)
}
}
2 changes: 1 addition & 1 deletion man/lagos_ingest.Rd

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

2 changes: 1 addition & 1 deletion man/lagosne_compile.Rd

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

12 changes: 12 additions & 0 deletions tests/testthat/test-lagos_load.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,15 @@ test_that("lagos_load fails well", {
"\n Try running the `lagosne_get` command."),
fixed = TRUE)
})

test_that("legacyids have non-scientific notation", {

skip_on_cran()
skip_on_travis()
skip_on_appveyor()

lakes_limno <- lagosne_load()$lakes_limno
expect_gt(
nchar(lakes_limno[lakes_limno$lagoslakeid == 448,]$legacyid),
11)# [1] "4.51733E+12"
})

0 comments on commit 0d16db9

Please sign in to comment.