-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: simplify read and fix IMGW tests
- Loading branch information
1 parent
549de33
commit 031aa30
Showing
12 changed files
with
98 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,5 @@ covr_report.html | |
lib | ||
docs | ||
pkgdown | ||
.Renviron | ||
.Renviron | ||
test-out.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#' Read IMGW hydrological and meteorological raw files that can be saved in different formats | ||
#' | ||
#' Internal function for reading IMGW files | ||
#' @param translit logical whether translit detected and iconv needed for reading | ||
#' @param fpath path to unzipped CSV-alike file | ||
#' | ||
#' @keywords internal | ||
#' @noRd | ||
|
||
imgw_read = function(translit, fpath) { | ||
|
||
if (translit) { | ||
data = as.data.frame(data.table::fread(cmd = paste("iconv -f ISO-8859-2 -t ASCII//TRANSLIT", fpath))) | ||
} else { | ||
data = tryCatch(expr = read.csv(fpath, header = FALSE, stringsAsFactors = FALSE, sep = ",", | ||
fileEncoding = "CP1250"), | ||
warning = function(w) { | ||
read.csv(fpath, header = FALSE, stringsAsFactors = FALSE, sep = ";") | ||
}) | ||
|
||
if (ncol(data) == 1) { | ||
data = tryCatch(expr = read.csv(fpath, header = FALSE, stringsAsFactors = FALSE, sep = ";", | ||
fileEncoding = "UTF-8"), | ||
warning = function(w) { | ||
read.csv(fpath, header = FALSE, stringsAsFactors = FALSE, sep = ";") | ||
}) | ||
} | ||
|
||
} | ||
return(data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,36 @@ | ||
context("meteo-metadata") | ||
|
||
test_that("tests to be re-written meteo_metadata_imgw", { | ||
test_that("meteo_metadata_imgw tests", { | ||
#skip("meteo-metadata skipping") | ||
if (!curl::has_internet()) { | ||
message("No internet connection! \n") | ||
return(invisible(NULL)) | ||
} else { | ||
m_hs <- meteo_metadata_imgw("hourly", "synop") | ||
m_hc <- meteo_metadata_imgw("hourly", "climate") | ||
m_ds <- meteo_metadata_imgw("daily", "synop") | ||
m_dc <- meteo_metadata_imgw("daily", "climate") | ||
m_dp <- meteo_metadata_imgw("daily", "precip") | ||
m_ms <- meteo_metadata_imgw("monthly", "synop") | ||
m_mc <- meteo_metadata_imgw("monthly", "climate") | ||
m_mp <- meteo_metadata_imgw("monthly", "precip") | ||
m_hs = meteo_metadata_imgw("hourly", "synop") | ||
m_hc = meteo_metadata_imgw("hourly", "climate") | ||
m_ds = meteo_metadata_imgw("daily", "synop") | ||
m_dc = meteo_metadata_imgw("daily", "climate") | ||
m_dp = meteo_metadata_imgw("daily", "precip") | ||
m_ms = meteo_metadata_imgw("monthly", "synop") | ||
m_mc = meteo_metadata_imgw("monthly", "climate") | ||
m_mp = meteo_metadata_imgw("monthly", "precip") | ||
|
||
expect_error(meteo_metadata_imgw("hourly", "precip")) | ||
expect_equal(dim(m_hs[[1]]), c(107, 3)) | ||
expect_equal(dim(m_hc[[1]]), c(22, 3)) | ||
expect_equal(dim(m_ds[[1]]), c(65, 3)) | ||
expect_equal(dim(m_ds[[2]]), c(23, 3)) | ||
expect_equal(dim(m_dc[[1]]), c(18, 3)) | ||
expect_equal(dim(m_dc[[2]]), c(13, 3)) | ||
expect_equal(dim(m_dp[[1]]), c(16, 3)) | ||
expect_equal(dim(m_ms[[1]]), c(60, 3)) | ||
expect_equal(dim(m_ms[[2]]), c(22, 3)) | ||
expect_equal(dim(m_mc[[1]]), c(27, 3)) | ||
expect_equal(dim(m_mc[[2]]), c(12, 3)) | ||
expect_equal(dim(m_mp[[1]]), c(14, 3)) | ||
|
||
if (is.list(m_hs) && is.list(m_ds) && is.list(m_ds) && is.list(m_dc) && | ||
is.list(m_dp) && is.list(m_ms) && is.list(m_mc) && is.list(m_mp)) { | ||
expect_equal(dim(m_hs[[1]]), c(107, 3)) | ||
expect_equal(dim(m_hc[[1]]), c(22, 3)) | ||
expect_equal(dim(m_ds[[1]]), c(65, 3)) | ||
expect_equal(dim(m_ds[[2]]), c(23, 3)) | ||
expect_equal(dim(m_dc[[1]]), c(18, 3)) | ||
expect_equal(dim(m_dc[[2]]), c(13, 3)) | ||
expect_equal(dim(m_dp[[1]]), c(16, 3)) | ||
expect_equal(dim(m_ms[[1]]), c(60, 3)) | ||
expect_equal(dim(m_ms[[2]]), c(22, 3)) | ||
expect_equal(dim(m_mc[[1]]), c(27, 3)) | ||
expect_equal(dim(m_mc[[2]]), c(12, 3)) | ||
expect_equal(dim(m_mp[[1]]), c(14, 3)) | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters