-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from darwin-eu/release_0_4_0
v0.4.0
- Loading branch information
Showing
119 changed files
with
5,037 additions
and
1,331 deletions.
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: omopgenerics | ||
Title: Methods and Classes for the OMOP Common Data Model | ||
Version: 0.3.1.900 | ||
Version: 0.4.0 | ||
Authors@R: c( | ||
person( | ||
"Martí", "Català", email = "[email protected]", | ||
|
@@ -39,6 +39,7 @@ Imports: | |
cli, | ||
dbplyr, | ||
dplyr, | ||
generics, | ||
glue, | ||
lifecycle, | ||
methods, | ||
|
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
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,78 @@ | ||
#' Add settings columns to a `<summarised_result>` object | ||
#' | ||
#' @param result A `<summarised_result>` object. | ||
#' @param settingsColumn Settings to be added as columns, by default | ||
#' `settingsColumns(result)` will be added. If NULL or empty character vector, | ||
#' no settings will be added. | ||
#' | ||
#' @export | ||
#' | ||
#' @return A `<summarised_result>` object with the added setting columns. | ||
#' @examples { | ||
#' library(dplyr) | ||
#' library(omopgenerics) | ||
#' | ||
#' x <- tibble( | ||
#' "result_id" = as.integer(c(1, 2)), | ||
#' "cdm_name" = c("cprd", "eunomia"), | ||
#' "group_name" = "cohort_name", | ||
#' "group_level" = "my_cohort", | ||
#' "strata_name" = "sex", | ||
#' "strata_level" = "male", | ||
#' "variable_name" = "Age group", | ||
#' "variable_level" = "10 to 50", | ||
#' "estimate_name" = "count", | ||
#' "estimate_type" = "numeric", | ||
#' "estimate_value" = "5", | ||
#' "additional_name" = "overall", | ||
#' "additional_level" = "overall" | ||
#' ) |> | ||
#' newSummarisedResult(settings = tibble( | ||
#' "result_id" = c(1, 2), "custom" = c("A", "B") | ||
#' )) | ||
#' | ||
#' x | ||
#' | ||
#' x |> addSettings() | ||
#' } | ||
#' | ||
addSettings <- function(result, | ||
settingsColumn = settingsColumns(result)) { | ||
# checks | ||
if (is.null(attr(result, "settings"))) { | ||
cli::cli_abort("result doesn't have a `settings` attribute") | ||
} | ||
settingsColumn <- checkSettingsColumns(settingsColumn, result) | ||
set <- settings(result) | ||
|
||
if (length(settingsColumn) == 0) { | ||
return(result) | ||
} | ||
|
||
# add settings | ||
toJoin <- settingsColumn[settingsColumn %in% colnames(result)] | ||
result <- result |> | ||
dplyr::left_join( | ||
set |> | ||
dplyr::select(dplyr::any_of(c("result_id", settingsColumn))), | ||
by = c("result_id", toJoin) | ||
) | ||
|
||
return(result) | ||
} | ||
|
||
checkSettingsColumns <- function(settingsColumns, result, call = parent.frame()) { | ||
set <- settings(result) | ||
assertCharacter(x = settingsColumns, null = TRUE, call = call) | ||
if (!is.null(settingsColumns)) { | ||
assertTable(set, columns = settingsColumns) | ||
settingsColumns <- settingsColumns[settingsColumns != "result_id"] | ||
notPresent <- settingsColumns[!settingsColumns %in% colnames(set)] | ||
if (length(notPresent) > 0) { | ||
cli::cli_abort("The following `settings` are not present in settings attribute: {.var {notPresent}}.", call = call) | ||
} | ||
} else { | ||
settingsColumns <- character() | ||
} | ||
return(invisible(settingsColumns)) | ||
} |
Oops, something went wrong.