Commit 13b66d39 authored by bob's avatar bob
Browse files

Parse date type when reading raw data

When reading raw data every columns were parse as character.
Now data type is preserved when parsing.
parent 47e69a19
......@@ -145,8 +145,8 @@ read_data_sheet <- function(file, sheet) {
# The first line is skipped. Otherwise the special place holder '$'
# separating variable name and unit might get coerced to a '.'
switch(file$extension,
"csv" = read.csv(file$path, header = FALSE),
"xlsx" = read.xlsx(file$path, sheet = sheet, colNames = FALSE)
"csv" = read.csv(file$path, check.names = FALSE),
"xlsx" = read.xlsx(file$path, sheet = sheet)
)
}
......@@ -165,7 +165,7 @@ read_data_sheet <- function(file, sheet) {
process_sheet <- function(file, sheet) {
dat <- read_data_sheet(file, sheet)
header <- strsplit(as.character(dat[1, ]), "\\$")
header <- strsplit(colnames(dat), "\\$")
empty_columns <- vapply(header, length, FUN.VALUE = integer(1)) == 0
if (any(empty_columns)) {
......@@ -177,10 +177,8 @@ process_sheet <- function(file, sheet) {
variables <- vapply(header, `[`, 1, FUN.VALUE = character(1)) # variable names
units <- vapply(header, `[`, 2, FUN.VALUE = character(1)) # units
# Assign variable names as column names
names(dat) <- variables
# and delete the first row (== header)
dat <- dat[-1, ]
# Assign variable names as column names -> get rid of $<unit>
colnames(dat) <- variables
processed_sheet <- list(
name = sheet,
......
......@@ -57,9 +57,16 @@ load_snapshot <- function(path_corresponding_file) {
#' Custom testthat expectation
#'
#' @param file A character string, name of the metadata workbook to check.
expect_macth_snapshot <- function(file) {
expect_match_snapshot <- function(file) {
path_file <- file.path("data/processed/", file)
snapshot <- load_snapshot(path_file)
wb <- read_metadata_wb(path_file)
testthat::expect_identical(wb, snapshot)
}
compare_with_snapshot <- function(file) {
path_file <- file.path("data/processed/", file)
snapshot <- load_snapshot(path_file)
wb <- read_metadata_wb(path_file)
waldo::compare(snapshot, wb)
}
......@@ -4,7 +4,9 @@ source("scripts/tests/snapshot.R")
# take_snapshot_processed_data()
testthat::test_that("Metadata wb matching snapshots", {
expect_macth_snapshot("example_data_metadata.xlsx")
expect_macth_snapshot("Meststof proef WUR_metadata.xlsx")
expect_match_snapshot("example_data_metadata.xlsx")
expect_match_snapshot("Meststof proef WUR_metadata.xlsx")
})
# compare_with_snapshot("example_data_metadata.xlsx")
# compare_with_snapshot("Meststof proef WUR_metadata.xlsx")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment