Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/type #129

Merged
merged 3 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ TARBALL=${PACKAGE}_${VERSION}.tar.gz
PKGDIR=.
CHKDIR=.

testn:
Rscript inst/validation/latest.R

# development cycle - bumps the version and tags based on version
bump-dev:
Rscript -e 'usethis::use_version("dev")'
Expand Down
12 changes: 7 additions & 5 deletions R/load_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,6 @@ unpack_col <- function(x) {
if(.no("short",x)) {
x[["short"]] <- x[["col"]]
}
if(.no("type", x)) {
x[["type"]] <- "numeric"
}
x <- unpack_about(x)
x$continuous <- .has("range",x)
if(x$continuous) {
Expand All @@ -349,8 +346,13 @@ unpack_col <- function(x) {
if(!.has("decode",x)) {
x$decode <- names(x$values)
}
x$values <- sapply(x$values, sub_null_natom, USE.NAMES=FALSE)
if(is.character(x$values)) x$type <- "character"
x$values <- sapply(x$values, sub_null_natom, USE.NAMES = FALSE)
if(is.character(x$values) && .no("type", x)) {
x$type <- "character"
}
}
if(.no("type", x)) {
x[["type"]] <- "numeric"
}
if(.has("source", x)) {
x$source <- paste0(x$source, collapse = " ")
Expand Down
15 changes: 15 additions & 0 deletions inst/validation/latest.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
library(yaml)

x <- yaml.load_file("inst/validation/yspec-stories.yaml")

stories <- names(x)
stories <- sub("YSP-S", "", stories)
stories <- as.integer(stories)

tests <- unlist(lapply(x, function(x) x$tests), use.names=FALSE)
dupt <- any(duplicated(tests))
tests <- sub("YSP-TEST-", "", tests)
tests <- as.integer(tests)

message("last story: ", max(stories))
message("last test: ", max(tests))
10 changes: 10 additions & 0 deletions inst/validation/yspec-stories.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
YSP-S034:
name: ys_load - only assume character type if type is NULL
description: >
As a user, I want yspec to infer that type is character for discrete
data when type is missing and the values field has type character.
ProductRisk: low-risk
tests: YSP-TEST-0145


# --------
YSP-S001:
name: Make ys_get_short_unit return list
description: ys_get_short_unit returns list not character vector
Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/test-load_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,19 @@ test_that("Error when values is mis-coded as list of lists [YSP-TEST-0072]", {
)
})

test_that("ys_load - only assume character type if type is NULL [YSP-TEST-0145]", {
spec <- yspec:::test_spec_list(
list(A = list(values = letters[1:3]))
)
expect_equal(spec$A$type, "character")

spec <- yspec:::test_spec_list(
list(A = list(values = c(1,2,3), type = "integer"))
)
expect_equal(spec$A$type, "integer")

spec <- yspec:::test_spec_list(
list(A = list(values = letters[1:3], type = "integer"))
)
expect_equal(spec$A$type, "integer")
})