Skip to content

Commit

Permalink
Merge pull request #247 from oxford-pharmacoepi/final_chanes_010
Browse files Browse the repository at this point in the history
tableSequenceRatio() vignette
  • Loading branch information
xihang-chen authored May 29, 2024
2 parents d192b71 + 4d510ab commit bf525a9
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 14 deletions.
12 changes: 6 additions & 6 deletions R/displayTables.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ tableSequenceRatios <- function(result,
Index = stringr::str_to_sentence(gsub("_", " ", .data$Index)),
Marker = stringr::str_to_sentence(gsub("_", " ", .data$Marker))
) %>%
{if (!indexName) {
dplyr::select(., -"Index")
} else .} %>%
{if (!markerName) {
dplyr::select(., -"Marker")
} else .} %>%
# {if (!indexName) {
# dplyr::select(., -"Index")
# } else .} %>%
# {if (!markerName) {
# dplyr::select(., -"Marker")
# } else .} %>%
tidyr::pivot_wider(names_from = "estimate_name", values_from = "estimate_value") %>%
dplyr::select(dplyr::all_of(order_columns))

Expand Down
97 changes: 92 additions & 5 deletions tests/testthat/test-displayTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ test_that("tableSequenceRatios - tibble output", {
test_that("tableSequenceRatios - flextable output", {
cdm <- mockCohortSymmetry()
cdm <- generateSequenceCohortSet(cdm = cdm,
indexTable = "cohort_1",
indexId = 1,
markerTable = "cohort_2",
markerId = 3,
name = "joined_cohort")
indexTable = "cohort_1",
indexId = 1,
markerTable = "cohort_2",
markerId = 3,
name = "joined_cohort")

res <- summariseSequenceRatios(cohort = cdm$joined_cohort, minCellCount = 0)

Expand All @@ -73,3 +73,90 @@ test_that("tableSequenceRatios - flextable output", {
cdmName = FALSE))
CDMConnector::cdmDisconnect(cdm)
})

test_that("tableSequenceRatio options", {
cdm <- mockCohortSymmetry()
cdm <- generateSequenceCohortSet(cdm = cdm,
indexTable = "cohort_1",
markerTable = "cohort_2",
name = "joined_cohort")

expect_warning(
result <- summariseSequenceRatios(cohort = cdm$joined_cohort, minCellCount = 0)
)

expect_no_error(
tableSequenceRatios(result = result,
.options = NULL)
)

expect_error(
tableSequenceRatios(result = result,
.options = list(titless = "Title"))
)

expect_no_error(
tableSequenceRatios(result = result,
.options = list(
groupColumn = c("cdm_name")
)))

expect_no_error(
tableSequenceRatios(result = result,
.options = list(bigMark = " < "))
)

expect_no_error(
tableSequenceRatios(result = result,
.options = list(decimalMark = " < "))
)

expect_no_error(
tableSequenceRatios(result = result,
.options = list(keepNotFormatted = F))
)

expect_no_error(
tableSequenceRatios(result = result,
.options = list(useFormatOrder = F))
)

expect_no_error(
tableSequenceRatios(result = result,
.options = list(includeHeaderName = T))
)

expect_no_error(
tableSequenceRatios(result = result,
.options = list(includeHeaderKey = F))
)

expect_no_error(
tableSequenceRatios(result = result,
.options = list(title = "Title"))
)

expect_no_error(
tableSequenceRatios(result = result,
.options = list(
title = "Title",
subtitle = "Subtitle"))
)

expect_no_error(
tableSequenceRatios(result = result,
.options = list(caption = "caption"))
)

expect_no_error(
tableSequenceRatios(result = result,
.options = list(na = "NA"))
)

expect_no_error(
tableSequenceRatios(result = result,
.options = list(groupAsColumn = T))
)

CDMConnector::cdm_disconnect(cdm = cdm)
})
14 changes: 14 additions & 0 deletions tests/testthat/test-summariseSequenceRatios.R
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,20 @@ test_that("min cell count",{
)
)

expect_error(
result_error <- summariseSequenceRatios(
cohort = cdm$joined_cohort,
minCellCount = Inf
)
)

expect_error(
result_error2 <- summariseSequenceRatios(
cohort = cdm$joined_cohort,
minCellCount = -1
)
)

expect_no_error(
expect_warning(
result2 <- summariseSequenceRatios(
Expand Down
22 changes: 19 additions & 3 deletions vignettes/a04_Visualise_sequence_ratios.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,34 @@ The function `tableSequenceRatios` inputs the result from `summariseSequenceRati
tableSequenceRatios(result = result)
```

By default, it has many columns such as Index (name), Marker (name), Study population, CSR and ASR, each of these columns could be suppressed with relevant parameters. For example if one wants to not display study population, one could do the following:

## Arguments used to suppress columns

By default, it has many columns such as Index (name), Marker (name), Study population, CSR and ASR, some of these columns could be suppressed with relevant parameters. For example if one wants to not display study population, one could do the following:

```{r message= FALSE, warning=FALSE}
tableSequenceRatios(result = result,
studyPopulation = FALSE)
```

Or suppress `cdmName` like so

```{r message= FALSE, warning=FALSE}
tableSequenceRatios(result = result,
cdmName = FALSE)
```

There are also `.options` argument that one may wish to specify. For example, the user can specify a title:

```{r message= FALSE, warning=FALSE}
tableSequenceRatios(result = result,
.options = list(title = "Title"))
```

Similarly, `subtitle` and `caption` can also be defined this way.

## Modify `type`

Instead of a gt table, the user may also want to put the sequence ratio results in a flex table format:
Instead of a gt table, the user may also want to put the sequence ratio results in a flex table format (the rest of the arguments that we saw for a gt table also applies here):

```{r message= FALSE, warning=FALSE}
tableSequenceRatios(result = result,
Expand Down

0 comments on commit bf525a9

Please sign in to comment.