diff --git a/DESCRIPTION b/DESCRIPTION index d673351..91393ae 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: mighty.component Title: Mighty Components for ADaM Generation -Version: 0.0.0.9017 +Version: 0.0.0.9018 Authors@R: c( person("Aksel", "Thomsen", , "oath@enovonordisk.com", role = c("aut", "cre")), person("Matthew", "Phelps", , "mewp@enovonordisk.com", role = c("aut")), diff --git a/R/mighty_component.R b/R/mighty_component.R index 6298ee7..fc8f433 100644 --- a/R/mighty_component.R +++ b/R/mighty_component.R @@ -215,7 +215,7 @@ tags_to_params <- function(tags) { tags_to_depends <- function(tags) { i <- regexpr(pattern = " +", text = tags) - data.frame( + depends <- data.frame( domain = tags |> substr(start = 1, stop = i - 1) |> trimws(), @@ -223,6 +223,18 @@ tags_to_depends <- function(tags) { substr(start = i + 1, stop = nchar(tags)) |> trimws() ) + + mistakes <- tags[!nchar(depends$domain) | !nchar(depends$column)] + if (length(mistakes)) { + cli::cli_abort( + c( + "All {.code @depends} tags must have both a domain and column:", + "x" = "Not valid: {.code {mistakes}}" + ) + ) + } + + depends } #' @noRd diff --git a/tests/testthat/_components/test_coverage.mustache b/tests/testthat/_components/test_coverage.mustache index f547577..cee8bfe 100644 --- a/tests/testthat/_components/test_coverage.mustache +++ b/tests/testthat/_components/test_coverage.mustache @@ -2,7 +2,7 @@ #' @description #' This is a test component used for unit testing the workflow and coverage. #' @param value to assign to x -#' @depends limit +#' @depends domain limit #' @type derivation #' @code x <- {{ value }} diff --git a/tests/testthat/test-mighty_component.R b/tests/testthat/test-mighty_component.R index 8c85601..f578984 100644 --- a/tests/testthat/test-mighty_component.R +++ b/tests/testthat/test-mighty_component.R @@ -181,6 +181,12 @@ test_that("tags_to_depends", { expect_named(c("domain", "column")) |> nrow() |> expect_equal(0) + + tags_to_depends("USUBJID") |> + expect_error("must have both a domain and column") + + tags_to_depends(c("data1 var1", "USUBJID")) |> + expect_error("must have both a domain and column") }) test_that("print", {