Skip to content

Commit

Permalink
Merge branch 'meta_inherit' of https://github.com/Merck/metalite into…
Browse files Browse the repository at this point in the history
… meta_inherit
  • Loading branch information
elong0527 committed Oct 24, 2023
2 parents 9d13e88 + fe7579c commit 95ff7c6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
24 changes: 12 additions & 12 deletions R/meta_inherit.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,33 @@
#' @return A metadata object with population defined.
#'
#' @examples
#' meta_adam(population = r2rtf::r2rtf_adsl,
#' observation = r2rtf::r2rtf_adae) |>
#' meta_adam(
#' population = r2rtf::r2rtf_adsl,
#' observation = r2rtf::r2rtf_adae
#' ) |>
#' meta_inherit(meta_example(), c("apat", "wk12", "ae_summary"))
#'
#' @export
meta_inherit <- function(
meta,
inherit,
name,
overwrite = FALSE
){

overwrite = FALSE) {
mapping <- list()
for(i in seq_along(name)){
for (i in seq_along(name)) {
x <- collect_adam_mapping(inherit, name[i])
if(is.null(x)){
stop(name[i],": keyword is not defined in the `inherit` meta information")
}else{
if (is.null(x)) {
stop(name[i], ": keyword is not defined in the `inherit` meta information")
} else {
mapping[[i]] <- x
}
}

for(i in seq_along(mapping)){
if(is.null(collect_adam_mapping(meta, name[[i]])) | overwrite){
for (i in seq_along(mapping)) {
if (is.null(collect_adam_mapping(meta, name[[i]])) | overwrite) {
meta[[mapping[[i]][[".location"]]]][[name[[i]]]] <- mapping[[i]]
}
}

meta
}
}
13 changes: 8 additions & 5 deletions tests/testthat/test-independent-testing-meta_inherit.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

test_that("Inherit keywords", {
x <- meta_adam(population = r2rtf::r2rtf_adsl,
observation = r2rtf::r2rtf_adae) |>
x <- meta_adam(
population = r2rtf::r2rtf_adsl,
observation = r2rtf::r2rtf_adae
) |>
meta_inherit(meta_example(), c("apat", "wk12", "ae_summary"))

expect_equal(names(x$population), "apat")
Expand All @@ -11,8 +12,10 @@ test_that("Inherit keywords", {

test_that("Wrong key words", {
expect_error(
meta_adam(population = r2rtf::r2rtf_adsl,
observation = r2rtf::r2rtf_adae) |>
meta_adam(
population = r2rtf::r2rtf_adsl,
observation = r2rtf::r2rtf_adae
) |>
meta_inherit(meta_example(), c("apat", "wk12", "ae_ser"))
)
})

0 comments on commit 95ff7c6

Please sign in to comment.