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

Use %in% to compare strings to gracefully deal with NAs #124

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: epireview
Title: Tools to update and summarise the latest pathogen data from the Pathogen Epidemiology Review Group (PERG)
Version: 1.3.4
Version: 1.3.5
Authors@R: c(
person("Rebecca", "Nash", email = "r.nash@imperial.ac.uk", role = "aut",
comment = c(ORCID = "0000-0002-5213-4364")),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# epireview 1.3.5

* BUG-FIX: Fixes #117. NA rows were being created because filter_df_for_metamean used == to compare strings, leading to NAs being created when the RHS was NA. Comparison now is being done using %in%.

# epireview 1.3.4

* DATA: Adds SARS-CoV-1 data (articles, models, and parameters). Outbreaks were not extracted.
Expand Down
10 changes: 5 additions & 5 deletions R/filter_df_for_metamean.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ filter_df_for_metamean <- function(df) {

df <- df[!is.na(df[["population_sample_size"]]), ]
df <- df[!is.na(df[["parameter_value"]]), ]
df <- df[df[["parameter_value_type"]] == 'Mean' &
df <- df[df[["parameter_value_type"]] %in% 'Mean' &
grepl(x = tolower(df[["parameter_uncertainty_singe_type"]]),
pattern = 'standard deviation') |
df[["parameter_value_type"]] == 'Median' &
df[["parameter_value_type"]] %in% 'Median' &
grepl(x = tolower(df[["parameter_uncertainty_type"]]),
pattern = 'iqr') |
df[["parameter_value_type"]] == 'Median' &
df[["parameter_value_type"]] %in% 'Median' &
grepl(x = tolower(df[["parameter_uncertainty_type"]]),
pattern = 'range'), ]

df$xbar <- ifelse(
df[["parameter_value_type"]] == "Mean", df[["parameter_value"]], NA
df[["parameter_value_type"]] %in% "Mean", df[["parameter_value"]], NA
)
df$median <- ifelse(
df[["parameter_value_type"]] == "Median", df[["parameter_value"]], NA
df[["parameter_value_type"]] %in% "Median", df[["parameter_value"]], NA
)
df$q1 <- ifelse(
grepl(x = tolower(df[["parameter_uncertainty_type"]]), "iqr"),
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-filter_df_for_metamean.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,12 @@ test_that("filtering parameter dataframe for meta mean works",{
expect_true(all(!is.na(out$population_sample_size)))
expect_true(all(!is.na(out$parameter_value)))
expect_true(all(!is.na(out$parameter_unit)))

## This dataset should have 17 rows after it is filtered through
## filter_df_for_metamean
x <- test_path("testdata", "offending_dataset.csv")
df <- read_csv(x, show_col_types = FALSE)
out <- filter_df_for_metamean(df)
expect_equal(dim(out)[1], 17L)
expect_true(all(!is.na(out$id)))
})
Loading
Loading