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

Closes #101 add get keys function #102

Merged
merged 4 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Authors@R:
role = "aut",
email = "mike.stackhouse@atorusresearch.com",
comment = c(ORCID = "0000-0001-6030-723X")),
person(given = "Tamara",
family = "Senior",
role = "aut",
email = "tamara.senior@roche.com"),
person(given = "GSK/Atorus JPT",
role = c("cph", "fnd")))
Description: Create an immutable container holding metadata for the purpose of better enabling programming activities and functionality of other packages within the clinical programming workflow.
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export(check_inconsistent_types)
export(create_tbl)
export(define_to_metacore)
export(get_control_term)
export(get_keys)
export(is_metacore)
export(load_metacore)
export(metacore)
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Metacroe 0.1.2
# Metacore 0.1.3
- Add `get_keys` function which returns the dataset keys for a given dataset

# Metacore 0.1.2
- Update to resolve issues from the dplyr updates

# Metacore 0.1.1
Expand Down
36 changes: 36 additions & 0 deletions R/metacore.R
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,42 @@ get_control_term <- function(metacode, variable, dataset = NULL){
}


#' Get Dataset Keys
#'
#' Returns the dataset keys for a given dataset
#'
#' @param metacode metacore object
#' @param dataset A dataset name
#'
#' @return a 2-column tibble with dataset key variables and key sequence
#' @export
#'
#' @importFrom rlang as_label enexpr as_name
#'
#' @examples
#' \dontrun{
#' meta_ex <- spec_to_metacore(metacore_example("p21_mock.xlsx"))
#' get_keys(meta_ex, "AE")
tamarasenior marked this conversation as resolved.
Show resolved Hide resolved
#' }
get_keys <- function(metacode, dataset){
dataset_val <- ifelse(str_detect(as_label(enexpr(dataset)), "\""),
as_name(dataset), as_label(enexpr(dataset))) # to make the filter more explicit

subset_data <- metacode$ds_vars %>%
filter(dataset == dataset_val)
if(nrow(subset_data) == 0){
stop(paste0(dataset_val, " not found in the value_spec table. Please check the dataset name"))
}

keys <- subset_data %>%
filter(!is.na(key_seq)) %>%
select(variable, key_seq)

keys <- keys[order(keys$key_seq),]

return(keys)
}


#' save metacore object
#'
Expand Down
25 changes: 25 additions & 0 deletions man/get_keys.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading