Skip to content

Commit

Permalink
fixing R check
Browse files Browse the repository at this point in the history
fixing R check
  • Loading branch information
jreps committed Oct 2, 2023
1 parent 7993a6e commit 2989f9f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 63 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ Imports:
shiny,
shinycssloaders,
shinydashboard,
shinyjs,
shinyWidgets,
SqlRender,
stringi,
Expand Down
94 changes: 39 additions & 55 deletions R/characterization-incidence.R
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,6 @@ characterizationIncidenceServer <- function(
) {
shiny::moduleServer(
id,
#' Title
#'
#' @param input
#' @param output
#' @param session
#'
#' @return
#' @export
#'
#' @examples
function(input, output, session) {


Expand Down Expand Up @@ -573,15 +563,15 @@ characterizationIncidenceServer <- function(
connectionHandler = connectionHandler,
resultDatabaseSettings = resultDatabaseSettings

Check warning on line 564 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L561-L564

Added lines #L561 - L564 were not covered by tests
) %>%
dplyr::relocate(tar, .before = outcomes) %>%
dplyr::mutate(incidenceProportionP100p = as.numeric(incidenceProportionP100p),
incidenceRateP100py = as.numeric(incidenceRateP100py),
dplyr::relocate("tar", .before = "outcomes") %>%
dplyr::mutate(incidenceProportionP100p = as.numeric(.data$incidenceProportionP100p),
incidenceRateP100py = as.numeric(.data$incidenceRateP100py),
dplyr::across(dplyr::where(is.numeric), round, 4),
targetIdShort = paste("C", targetCohortDefinitionId, sep = ":"),
outcomeIdShort = paste("C", outcomeCohortDefinitionId, sep = ":")) %>%
dplyr::filter(ageGroupName %in% inputSelected()$incidenceRateAgeFilter &
genderName %in% inputSelected()$incidenceRateGenderFilter &
startYear %in% inputSelected()$incidenceRateCalendarFilter
targetIdShort = paste("C", .data$targetCohortDefinitionId, sep = ":"),
outcomeIdShort = paste("C", .data$outcomeCohortDefinitionId, sep = ":")) %>%
dplyr::filter(.data$ageGroupName %in% !!inputSelected()$incidenceRateAgeFilter &
.data$genderName %in% !!inputSelected()$incidenceRateGenderFilter &
.data$startYear %in% !!inputSelected()$incidenceRateCalendarFilter

Check warning on line 574 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L566-L574

Added lines #L566 - L574 were not covered by tests
)
}
)
Expand Down Expand Up @@ -623,14 +613,9 @@ characterizationIncidenceServer <- function(
return(data.frame())
}

print(filteredData())
print(inputSelected()$incidenceRateTarFilter)

plotData <- filteredData() %>%
dplyr::filter(.data$tar %in% inputSelected()$incidenceRateTarFilter)

Check warning on line 617 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L616-L617

Added lines #L616 - L617 were not covered by tests

print(plotData)

# Take the specific tar value you want to plot
tar_value <- unique(plotData$tar)[1]

Check warning on line 620 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L620

Added line #L620 was not covered by tests

Expand All @@ -652,8 +637,7 @@ characterizationIncidenceServer <- function(
"Outcomes:", outcomes

Check warning on line 637 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L623-L637

Added lines #L623 - L637 were not covered by tests
))

print(plotData$tooltip)


# Check if color, size, shape, and trellis variables are selected, and set aesthetics accordingly
color_aesthetic <- NULL
size_aesthetic <- NULL
Expand All @@ -663,17 +647,17 @@ characterizationIncidenceServer <- function(

if (inputSelected()$plotColor == "Target Cohort" | inputSelected()$plotColor == "Outcome Cohort") {
color_aesthetic <- if (inputSelected()$plotColor == "Target Cohort") {
dplyr::vars(targetIdShort)
dplyr::vars(.data$targetIdShort)
} else if (inputSelected()$plotColor == "Outcome Cohort") {
dplyr::vars(outcomeIdShort)
dplyr::vars(.data$outcomeIdShort)

Check warning on line 652 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L648-L652

Added lines #L648 - L652 were not covered by tests
}
}

if (inputSelected()$plotShape == "Target Cohort" | inputSelected()$plotShape == "Outcome Cohort") {
shape_aesthetic <- if (inputSelected()$plotShape == "Target Cohort") {
dplyr::vars(targetIdShort)
dplyr::vars(.data$targetIdShort)
} else if (inputSelected()$plotShape == "Outcome Cohort") {
dplyr::vars(outcomeIdShort)
dplyr::vars(.data$outcomeIdShort)

Check warning on line 660 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L656-L660

Added lines #L656 - L660 were not covered by tests
}
}

Expand All @@ -692,7 +676,7 @@ characterizationIncidenceServer <- function(
color = if(inputSelected()$plotColor != "None" & inputSelected()$plotColor != "Target Cohort" &
inputSelected()$plotColor != "Outcome Cohort") .data[[inputSelected()$plotColor]]
else color_aesthetic,
text = tooltip
text = .data$tooltip

Check warning on line 679 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L669-L679

Added lines #L669 - L679 were not covered by tests
)
) +
ggplot2::geom_point(ggplot2::aes(size = if(inputSelected()$plotSize != "None") .data[[inputSelected()$plotSize]] else NULL,
Expand All @@ -709,8 +693,8 @@ characterizationIncidenceServer <- function(
if (inputSelected()$plotXTrellis!="None" & inputSelected()$plotXTrellis!="targetName" & inputSelected()$plotXTrellis!="outcomeName" &
inputSelected()$plotYTrellis!="None" & inputSelected()$plotYTrellis!="targetName" & inputSelected()$plotYTrellis!="outcomeName") {
base_plot <- base_plot + ggplot2::facet_grid(
rows = vars(.data[[inputSelected()$plotXTrellis]]),
cols = vars(.data[[inputSelected()$plotYTrellis]]),
rows = dplyr::vars(.data[[inputSelected()$plotXTrellis]]),
cols = dplyr::vars(.data[[inputSelected()$plotYTrellis]]),
scales = if (inputSelected()$irYscaleFixed) "fixed" else "free_y"

Check warning on line 698 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L693-L698

Added lines #L693 - L698 were not covered by tests
) +
ggplot2::theme(strip.background = ggplot2::element_blank(),
Expand All @@ -721,8 +705,8 @@ characterizationIncidenceServer <- function(
else if (inputSelected()$plotXTrellis!="None" & inputSelected()$plotXTrellis=="targetName" & inputSelected()$plotXTrellis!="outcomeName" &
inputSelected()$plotYTrellis!="None" & inputSelected()$plotYTrellis!="targetName" & inputSelected()$plotYTrellis!="outcomeName") {
base_plot <- base_plot + ggplot2::facet_grid(
rows = vars(targetIdShort),
cols = vars(.data[[inputSelected()$plotYTrellis]]),
rows = dplyr::vars(.data$targetIdShort),
cols = dplyr::vars(.data[[inputSelected()$plotYTrellis]]),
scales = if (inputSelected()$irYscaleFixed) "fixed" else "free_y"

Check warning on line 710 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L705-L710

Added lines #L705 - L710 were not covered by tests
) +
ggplot2::theme(strip.background = ggplot2::element_blank(),
Expand All @@ -733,8 +717,8 @@ characterizationIncidenceServer <- function(
else if (inputSelected()$plotXTrellis!="None" & inputSelected()$plotXTrellis!="targetName" & inputSelected()$plotXTrellis=="outcomeName" &
inputSelected()$plotYTrellis!="None" & inputSelected()$plotYTrellis!="targetName" & inputSelected()$plotYTrellis!="outcomeName") {
base_plot <- base_plot + ggplot2::facet_grid(
rows = vars(outcomeIdShort),
cols = vars(.data[[inputSelected()$plotYTrellis]]),
rows = dplyr::vars(.data$outcomeIdShort),
cols = dplyr::vars(.data[[inputSelected()$plotYTrellis]]),
scales = if (inputSelected()$irYscaleFixed) "fixed" else "free_y"

Check warning on line 722 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L717-L722

Added lines #L717 - L722 were not covered by tests
) +
ggplot2::theme(strip.background = ggplot2::element_blank(),
Expand All @@ -745,8 +729,8 @@ characterizationIncidenceServer <- function(
else if (inputSelected()$plotXTrellis!="None" & inputSelected()$plotXTrellis!="targetName" & inputSelected()$plotXTrellis!="outcomeName" &
inputSelected()$plotYTrellis!="None" & inputSelected()$plotYTrellis=="targetName" & inputSelected()$plotYTrellis!="outcomeName") {
base_plot <- base_plot + ggplot2::facet_grid(
rows = vars(.data[[inputSelected()$plotXTrellis]]),
cols = vars(targetIdShort),
rows = dplyr::vars(.data[[inputSelected()$plotXTrellis]]),
cols = dplyr::vars(.data$targetIdShort),
scales = if (inputSelected()$irYscaleFixed) "fixed" else "free_y"

Check warning on line 734 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L729-L734

Added lines #L729 - L734 were not covered by tests
) +
ggplot2::theme(strip.background = ggplot2::element_blank(),
Expand All @@ -757,8 +741,8 @@ characterizationIncidenceServer <- function(
else if (inputSelected()$plotXTrellis!="None" & inputSelected()$plotXTrellis!="targetName" & inputSelected()$plotXTrellis!="outcomeName" &
inputSelected()$plotYTrellis!="None" & inputSelected()$plotYTrellis!="targetName" & inputSelected()$plotYTrellis=="outcomeName") {
base_plot <- base_plot + ggplot2::facet_grid(
rows = vars(.data[[inputSelected()$plotXTrellis]]),
cols = vars(outcomeIdShort),
rows = dplyr::vars(.data[[inputSelected()$plotXTrellis]]),
cols = dplyr::vars(.data$outcomeIdShort),
scales = if (inputSelected()$irYscaleFixed) "fixed" else "free_y"

Check warning on line 746 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L741-L746

Added lines #L741 - L746 were not covered by tests
) +
ggplot2::theme(strip.background = ggplot2::element_blank(),
Expand All @@ -769,8 +753,8 @@ characterizationIncidenceServer <- function(
else if (inputSelected()$plotXTrellis!="None" & inputSelected()$plotXTrellis=="targetName" & inputSelected()$plotXTrellis!="outcomeName" &
inputSelected()$plotYTrellis!="None" & inputSelected()$plotYTrellis=="targetName" & inputSelected()$plotYTrellis!="outcomeName") {
base_plot <- base_plot + ggplot2::facet_grid(
rows = vars(targetIdShort),
cols = vars(targetIdShort),
rows = dplyr::vars(.data$targetIdShort),
cols = dplyr::vars(.data$targetIdShort),
scales = if (inputSelected()$irYscaleFixed) "fixed" else "free_y"

Check warning on line 758 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L753-L758

Added lines #L753 - L758 were not covered by tests
) +
ggplot2::theme(strip.background = ggplot2::element_blank(),
Expand All @@ -781,8 +765,8 @@ characterizationIncidenceServer <- function(
else if (inputSelected()$plotXTrellis!="None" & inputSelected()$plotXTrellis=="targetName" & inputSelected()$plotXTrellis!="outcomeName" &
inputSelected()$plotYTrellis!="None" & inputSelected()$plotYTrellis!="targetName" & inputSelected()$plotYTrellis=="outcomeName") {
base_plot <- base_plot + ggplot2::facet_grid(
rows = vars(targetIdShort),
cols = vars(outcomeIdShort),
rows = dplyr::vars(.data$targetIdShort),
cols = dplyr::vars(.data$outcomeIdShort),
scales = if (inputSelected()$irYscaleFixed) "fixed" else "free_y"

Check warning on line 770 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L765-L770

Added lines #L765 - L770 were not covered by tests
) +
ggplot2::theme(strip.background = ggplot2::element_blank(),
Expand All @@ -793,8 +777,8 @@ characterizationIncidenceServer <- function(
else if (inputSelected()$plotXTrellis!="None" & inputSelected()$plotXTrellis!="targetName" & inputSelected()$plotXTrellis=="outcomeName" &
inputSelected()$plotYTrellis!="None" & inputSelected()$plotYTrellis=="targetName" & inputSelected()$plotYTrellis!="outcomeName") {
base_plot <- base_plot + ggplot2::facet_grid(
rows = vars(outcomeIdShort),
cols = vars(targetIdShort),
rows = dplyr::vars(.data$outcomeIdShort),
cols = dplyr::vars(.data$targetIdShort),
scales = if (inputSelected()$irYscaleFixed) "fixed" else "free_y"

Check warning on line 782 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L777-L782

Added lines #L777 - L782 were not covered by tests
) +
ggplot2::theme(strip.background = ggplot2::element_blank(),
Expand All @@ -805,8 +789,8 @@ characterizationIncidenceServer <- function(
else if (inputSelected()$plotXTrellis!="None" & inputSelected()$plotXTrellis!="targetName" & inputSelected()$plotXTrellis=="outcomeName" &
inputSelected()$plotYTrellis!="None" & inputSelected()$plotYTrellis!="targetName" & inputSelected()$plotYTrellis=="outcomeName") {
base_plot <- base_plot + ggplot2::facet_grid(
rows = vars(outcomeIdShort),
cols = vars(outcomeIdShort),
rows = dplyr::vars(.data$outcomeIdShort),
cols = dplyr::vars(.data$outcomeIdShort),
scales = if (inputSelected()$irYscaleFixed) "fixed" else "free_y"

Check warning on line 794 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L789-L794

Added lines #L789 - L794 were not covered by tests
) +
ggplot2::theme(strip.background = ggplot2::element_blank(),
Expand All @@ -818,7 +802,7 @@ characterizationIncidenceServer <- function(
inputSelected()$plotYTrellis!="None" & inputSelected()$plotYTrellis!="targetName" & inputSelected()$plotYTrellis=="outcomeName") {
base_plot <- base_plot + ggplot2::facet_grid(
rows = NULL,
cols = vars(outcomeIdShort),
cols = dplyr::vars(.data$outcomeIdShort),
scales = if (inputSelected()$irYscaleFixed) "fixed" else "free_y"

Check warning on line 806 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L801-L806

Added lines #L801 - L806 were not covered by tests
) +
ggplot2::theme(strip.background = ggplot2::element_blank(),
Expand All @@ -830,7 +814,7 @@ characterizationIncidenceServer <- function(
inputSelected()$plotYTrellis!="None" & inputSelected()$plotYTrellis=="targetName" & inputSelected()$plotYTrellis!="outcomeName") {
base_plot <- base_plot + ggplot2::facet_grid(
rows = NULL,
cols = vars(targetIdShort),
cols = dplyr::vars(.data$targetIdShort),
scales = if (inputSelected()$irYscaleFixed) "fixed" else "free_y"

Check warning on line 818 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L813-L818

Added lines #L813 - L818 were not covered by tests
) +
ggplot2::theme(strip.background = ggplot2::element_blank(),
Expand All @@ -842,7 +826,7 @@ characterizationIncidenceServer <- function(
inputSelected()$plotYTrellis!="None" & inputSelected()$plotYTrellis!="targetName" & inputSelected()$plotYTrellis!="outcomeName") {
base_plot <- base_plot + ggplot2::facet_grid(
rows = NULL,
cols = vars(.data[[inputSelected()$plotYTrellis]]),
cols = dplyr::vars(.data[[inputSelected()$plotYTrellis]]),
scales = if (inputSelected()$irYscaleFixed) "fixed" else "free_y"

Check warning on line 830 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L825-L830

Added lines #L825 - L830 were not covered by tests
) +
ggplot2::theme(strip.background = ggplot2::element_blank(),
Expand All @@ -853,7 +837,7 @@ characterizationIncidenceServer <- function(
else if (inputSelected()$plotXTrellis!="None" & inputSelected()$plotXTrellis!="targetName" & inputSelected()$plotXTrellis!="outcomeName" &
inputSelected()$plotYTrellis=="None" & inputSelected()$plotYTrellis!="targetName" & inputSelected()$plotYTrellis!="outcomeName") {
base_plot <- base_plot + ggplot2::facet_grid(
rows = vars(.data[[inputSelected()$plotXTrellis]]),
rows = dplyr::vars(.data[[inputSelected()$plotXTrellis]]),
cols = NULL,
scales = if (inputSelected()$irYscaleFixed) "fixed" else "free_y"

Check warning on line 842 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L837-L842

Added lines #L837 - L842 were not covered by tests
) +
Expand All @@ -865,7 +849,7 @@ characterizationIncidenceServer <- function(
else if (inputSelected()$plotXTrellis!="None" & inputSelected()$plotXTrellis=="targetName" & inputSelected()$plotXTrellis!="outcomeName" &
inputSelected()$plotYTrellis=="None" & inputSelected()$plotYTrellis!="targetName" & inputSelected()$plotYTrellis!="outcomeName") {
base_plot <- base_plot + ggplot2::facet_grid(
rows = vars(targetIdShort),
rows = dplyr::vars(.data$targetIdShort),
cols = NULL,
scales = if (inputSelected()$irYscaleFixed) "fixed" else "free_y"

Check warning on line 854 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L849-L854

Added lines #L849 - L854 were not covered by tests
) +
Expand All @@ -877,7 +861,7 @@ characterizationIncidenceServer <- function(
else if (inputSelected()$plotXTrellis!="None" & inputSelected()$plotXTrellis!="targetName" & inputSelected()$plotXTrellis=="outcomeName" &
inputSelected()$plotYTrellis=="None" & inputSelected()$plotYTrellis!="targetName" & inputSelected()$plotYTrellis!="outcomeName") {
base_plot <- base_plot + ggplot2::facet_grid(
rows = vars(outcomeIdShort),
rows = dplyr::vars(.data$outcomeIdShort),
cols = NULL,
scales = if (inputSelected()$irYscaleFixed) "fixed" else "free_y"

Check warning on line 866 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L861-L866

Added lines #L861 - L866 were not covered by tests
) +
Expand Down Expand Up @@ -962,7 +946,7 @@ characterizationIncidenceServer <- function(
}

plotData <- filteredData() %>%
dplyr::filter(tar %in% inputSelected()$incidenceRateTarFilter)
dplyr::filter(.data$tar %in% inputSelected()$incidenceRateTarFilter)

Check warning on line 949 in R/characterization-incidence.R

View check run for this annotation

Codecov / codecov/patch

R/characterization-incidence.R#L948-L949

Added lines #L948 - L949 were not covered by tests

# Get the number of facets in both rows and columns
num_rows <- length(unique(plotData[[inputSelected()$plotXTrellis]]))
Expand Down
21 changes: 14 additions & 7 deletions tests/testthat/test-characterization-incidence.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,22 @@ shiny::testServer(
),
expr = {

# make sure cohorts is a data.frame
testthat::expect_true(class(cohorts) == 'list')
testthat::expect_true(!is.null(cohorts$targetIds))
testthat::expect_true(!is.null(cohorts$outcomeIds))
# make sure options is a list
testthat::expect_true(class(options) == 'list')
testthat::expect_true(!is.null(options$targetIds))
testthat::expect_true(!is.null(options$outcomeIds))

# check input$generate does not crash app
session$setInputs(`input-selection_targetId` = 1)
session$setInputs(`input-selection_outcomeId` = 3)
session$setInputs(`input-selection_generate` = T)
# need to test generate in ns("input-selection")
session$setInputs(`input-selection_generate` = 1)

idata <- getIncidenceData(
targetIds = options$targetIds[1],
outcomeIds = options$outcomeIds[1],
connectionHandler = connectionHandler,
resultDatabaseSettings = resultDatabaseSettings
)
testthat::expect_is(idata, 'data.frame')

})

Expand Down

0 comments on commit 2989f9f

Please sign in to comment.