-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
106 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates. | ||
# All rights reserved. | ||
# | ||
# This file is part of the metalite program. | ||
# | ||
# metalite is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#' Inherit meta information by keywords | ||
#' | ||
#' @param meta A `meta_adam` object. | ||
#' @param meta_inherit A `meta_adam` object to be inherit. | ||
#' @param name A vector of keywords from `meta_inherit` to `meta_adam`. | ||
#' @param overwrite A logical value to force mapping update. | ||
#' | ||
#' @return A metadata object with population defined. | ||
#' | ||
#' @examples | ||
#' 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 | ||
){ | ||
|
||
mapping <- list() | ||
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{ | ||
mapping[[i]] <- x | ||
} | ||
} | ||
|
||
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 | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,18 @@ | ||
|
||
test_that("Inherit keywords", { | ||
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") | ||
expect_equal(names(x$observation), "wk12") | ||
expect_equal(names(x$analysis), "ae_summary") | ||
}) | ||
|
||
test_that("Wrong key words", { | ||
expect_error( | ||
meta_adam(population = r2rtf::r2rtf_adsl, | ||
observation = r2rtf::r2rtf_adae) |> | ||
meta_inherit(meta_example(), c("apat", "wk12", "ae_ser")) | ||
) | ||
}) |