Skip to content

Commit

Permalink
Fix issue #195 and update corresponding messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Karim-Mane committed Nov 12, 2024
1 parent e318a53 commit f496618
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 43 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@
* Use {cli} package for formatting messages in the package (#196, Karim-Mane).

* Translate messages in the package into French using {potools} package (#196, Karim-Mane).

* An additional column (**row_id**) with the row indices where the incorrect date sequences are found is now added to the report made from the `check_date_sequence()` function (#196, Karim-Mane).
16 changes: 11 additions & 5 deletions R/check_date_sequence.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ check_date_sequence <- function(data, target_columns) {
cli::cli_abort(c(
tr_("Insufficient number of columns to compare."),
x = tr_("At least two columns of type {.cls Date} are required for this operation."), # nolint: line_length_linter
i = tr_("Did you enter an incorrect correct name?")
i = tr_("Have you provided an incorrect column name?")
), call = NULL)
}
}
Expand All @@ -75,16 +75,22 @@ check_date_sequence <- function(data, target_columns) {
bad_order <- which(!order_date)
if (!all(order_date)) {
tmp_data <- tmp_data[bad_order, ]
# add the row numbers of incorrect records to the report
tmp_data <- data.frame(
cbind(row_id = bad_order, tmp_data)
)
# adding incorrect records to the report
data <- add_to_report(
x = data,
key = "incorrect_date_sequence",
value = tmp_data
)
cli::cli_alert_info(
tr_("Detected {.val {length(bad_order)}} incorrect date sequence{?s} at line{?s}: {.val {toString(bad_order)}}."), # nolint: line_length_linter
wrap = TRUE
)

# send a message about the presence of incorrect date sequence
cli::cli_inform(c(
"!" = tr_("Detected {.val {length(bad_order)}} incorrect date sequence{?s} at line{?s}: {.val {toString(bad_order)}}."), # nolint: line_length_linter
i = tr_("Enter {.code attr(dat, \"report\")[[\"incorrect_date_sequence\"]]} to access them, where {.val dat} is the object used to store the output from this operation.") # nolint: line_length_linter
))
}

return(data)
Expand Down
Binary file modified inst/po/fr/LC_MESSAGES/R-cleanepi.mo
Binary file not shown.
19 changes: 9 additions & 10 deletions inst/rmarkdown/templates/printing-rmd/skeleton/skeleton.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,23 @@ incorrect_date_sequence <- params[["incorrect_date_sequence"]]
are_incorrect_date_seq_found <- !is.null(incorrect_date_sequence)
constant_data <- params[["constant_data"]]
are_constant_data_found <- !is.null(constant_data)
duplicated_rows <- params[["duplicated_rows"]]
duplicated_rows <- params[["duplicated_rows"]]
are_duplicates_found <- !is.null(duplicated_rows)
removed_duplicates <- params[["removed_duplicates"]]
removed_duplicates <- params[["removed_duplicates"]]
are_duplicates_removed <- !is.null(removed_duplicates)
misspelled_values <- params[["misspelled_values"]]
misspelled_values <- params[["misspelled_values"]]
are_misspelled_values_found <- !is.null(misspelled_values)
missing_values_replaced_at <- params[["missing_values_replaced_at"]]
missing_values_replaced_at <- params[["missing_values_replaced_at"]]
are_missing_values_replaced <- !is.null(missing_values_replaced_at)
incorrect_subject_id <- params[["incorrect_subject_id"]]
incorrect_subject_id <- params[["incorrect_subject_id"]]
are_incorrect_subject_id <- !is.null(incorrect_subject_id)
missing_ids <- params[["missing_ids"]]
missing_ids <- params[["missing_ids"]]
are_missing_ids <- !is.null(missing_ids)
duplicated_ids <- params[["duplicated_ids"]]
duplicated_ids <- params[["duplicated_ids"]]
are_duplicated_ids <- !is.null(duplicated_ids)
converted_into_numeric <- params[["converted_into_numeric"]]
converted_into_numeric <- params[["converted_into_numeric"]]
are_converted_into_numeric <- !is.null(converted_into_numeric)
incorrect_date_sequence <- params[["incorrect_date_sequence"]]
are_incorrect_date_sequence <- !is.null(incorrect_date_sequence)
incorrect_date_sequence <- params[["incorrect_date_sequence"]]
multi_format_dates <- params[["multi_format_dates"]]
are_multi_format_dates <- !is.null(multi_format_dates)
```
Expand Down
13 changes: 10 additions & 3 deletions po/R-cleanepi.pot
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: cleanepi 1.0.2.9000\n"
"POT-Creation-Date: 2024-11-12 13:40+0000\n"
"POT-Creation-Date: 2024-11-12 16:13+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -26,15 +26,22 @@ msgid ""
msgstr ""

#: check_date_sequence.R:67
msgid "Did you enter an incorrect correct name?"
msgid "Have you provided an incorrect column name?"
msgstr ""

#: check_date_sequence.R:85
#: check_date_sequence.R:91
msgid ""
"Detected {.val {length(bad_order)}} incorrect date sequence{?s} at line{?s}: "
"{.val {toString(bad_order)}}."
msgstr ""

#: check_date_sequence.R:92
msgid ""
"Enter {.code attr(dat, \"report\")[[\"incorrect_date_sequence\"]]} to access "
"them, where {.val dat} is the object used to store the output from this "
"operation."
msgstr ""

#: clean_data.R:139
msgid "cleaning column names"
msgstr ""
Expand Down
16 changes: 13 additions & 3 deletions po/R-fr.po
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: cleanepi 1.0.2.9000\n"
"POT-Creation-Date: 2024-11-12 13:40+0000\n"
"POT-Creation-Date: 2024-11-12 16:07+0000\n"
"PO-Revision-Date: 2024-11-07 12:38+0000\n"
"Last-Translator: Karim Mané\n"
"Language-Team: none\n"
Expand Down Expand Up @@ -30,17 +30,27 @@ msgstr ""
"Cette opération nécessite au moins deux noms de colonnes de type {.cls Date}."

#: check_date_sequence.R:67
msgid "Did you enter an incorrect correct name?"
msgid "Have you provided an incorrect column name?"
msgstr "Avez-vous fourni un nom de colonne incorrect?"

#: check_date_sequence.R:85
#: check_date_sequence.R:91
msgid ""
"Detected {.val {length(bad_order)}} incorrect date sequence{?s} at line{?s}: "
"{.val {toString(bad_order)}}."
msgstr ""
"La séquence des dates est incorrecte à travers les {.val "
"{length(bad_order)}} lignes suivantes: {.val {toString(bad_order)}}."

#: check_date_sequence.R:92
msgid ""
"Enter {.code attr(dat, \"report\")[[\"incorrect_date_sequence\"]]} to access "
"them, where {.val dat} is the object used to store the output from this "
"operation."
msgstr ""
"Veuillez entrer {.code attr(dat, \"report\")[[\"incorrect_date_sequence\"]]} "
"pour y accéder. {.val dat} represente ici l'object créé pour stocker le "
"résultat de cette opération."

#: clean_data.R:139
msgid "cleaning column names"
msgstr "nettoyage des noms de colonnes"
Expand Down
50 changes: 28 additions & 22 deletions tests/testthat/test-check_date_sequence.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
test_that("is_date_sequence_ordered works as expected", {
x <- as.Date(c("2023-10-02", "2023-10-10", "2023-10-20"))
x <- as.Date(c("2023-10-02", "2023-10-10", "2023-10-20"))
res <- is_date_sequence_ordered(x)
expect_true(res)
})

test_that("is_date_sequence_ordered works as expected", {
x <- as.Date(c("2023-10-02", "2023-10-20", "2023-10-10"))
x <- as.Date(c("2023-10-02", "2023-10-20", "2023-10-10"))
res <- is_date_sequence_ordered(x)
expect_false(res)
})
Expand All @@ -16,49 +16,54 @@ data <- readRDS(system.file("extdata", "test_df.RDS", package = "cleanepi"))
# standardize the date values
data <- data %>%
standardize_dates(
target_columns = c("date_first_pcr_positive_test",
"date.of.admission"),
target_columns = c("date_first_pcr_positive_test", "date.of.admission"),
error_tolerance = 0.4,
format = NULL,
timeframe = NULL
format = NULL,
timeframe = NULL
)

test_that("check_date_sequence sends a warning when incorrect column nams are
found", {
expect_message(
check_date_sequence(
data = data,
target_columns = c("date_first_pcr_positive_test",
"date.of.admission", "fake_name")
data = data,
target_columns = c(
"date_first_pcr_positive_test", "date.of.admission",
"fake_name"
)
),
regexp = cat("Found the following unrecognised column name:
`fake_name`")
)

expect_message(
check_date_sequence(
data = data,
target_columns = c("date_first_pcr_positive_test",
"date.of.admission") ),
data = data,
target_columns = c(
"date_first_pcr_positive_test", "date.of.admission"
)
),
regexp = cat("Detected 2 incorrect date sequences at
lines: `6, 8`")
)

expect_error(
check_date_sequence(
data = data,
target_columns = c("date_first_pcr_positive_test",
"fake_name")),
data = data,
target_columns = c(
"date_first_pcr_positive_test", "fake_name")
),
regexp = cat("Insufficient number of columns to compare.")
)
})

test_that("check_date_sequence works as expected when target_column is provided
as a vector", {
good_date_sequence <- check_date_sequence(
data = data,
target_columns = c("date_first_pcr_positive_test",
"date.of.admission")
data = data,
target_columns = c(
"date_first_pcr_positive_test", "date.of.admission"
)
)
report <- attr(good_date_sequence, "report")
expect_s3_class(good_date_sequence, "data.frame")
Expand All @@ -68,8 +73,9 @@ test_that("check_date_sequence works as expected when target_column is provided
c("multi_format_dates", "incorrect_date_sequence"))
expect_s3_class(report[["incorrect_date_sequence"]], "data.frame")
expect_identical(nrow(report[["incorrect_date_sequence"]]), 2L)
expect_identical(ncol(report[["incorrect_date_sequence"]]), 2L)
expect_identical(names(report[["incorrect_date_sequence"]]),
c("date_first_pcr_positive_test",
"date.of.admission"))
expect_identical(ncol(report[["incorrect_date_sequence"]]), 3L)
expect_identical(
names(report[["incorrect_date_sequence"]]),
c("row_id", "date_first_pcr_positive_test", "date.of.admission")
)
})

0 comments on commit f496618

Please sign in to comment.