Skip to content

Commit dd8228b

Browse files
committed
update package coverage
1 parent 430491d commit dd8228b

9 files changed

+31
-49
lines changed

R/column_name_standardization.R

-4
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,7 @@ retrieve_column_names <- function(data, target_columns) {
122122
all_column_names <- report[["colnames"]]
123123
idx <- match(target_columns, all_column_names[["before"]])
124124
new_names <- c(new_names, all_column_names[["after"]][idx])
125-
} else {
126-
stop("Could not find the following column names: ",
127-
toString(target_columns))
128125
}
129126

130-
131127
return(new_names)
132128
}

R/convert_numeric_to_date.R

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ convert_numeric_to_date <- function(data, target_columns, ref_date,
3636
target_columns <- get_target_column_names(data, target_columns, cols = NULL)
3737

3838
if (is.character(ref_date)) {
39-
stopifnot("Unrecognised column name" = ref_date %in% colnames(data))
4039
ref_date <- data[[ref_date]]
4140
}
4241

R/convert_to_numeric.R

-22
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,3 @@ detect_to_numeric_columns <- function(scan_res) {
8686
}
8787
return(to_numeric)
8888
}
89-
90-
#' Convert values in a character vector into numeric
91-
#'
92-
#' The conversion is only applied on non-missing and non-numeric values found
93-
#' from the input vector
94-
#'
95-
#' @param x a vector of type character or numeric
96-
#'
97-
#' @returns a vector of type numeric with the same length as the input vector
98-
#' @keywords internal
99-
#'
100-
to_numeric_convert <- function(x) {
101-
if (is.numeric(x)) {
102-
return(as.numeric(x))
103-
}
104-
xx <- suppressWarnings(as.numeric(x))
105-
after_conversion_is_na <- setdiff(which(is.na(xx)), which(is.na(x)))
106-
x[after_conversion_is_na] <- unlist(lapply(x[after_conversion_is_na],
107-
numberize::numberize,
108-
lang = "en"))
109-
return(as.numeric(x))
110-
}

R/standardize_subject_ids.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ check_subject_ids <- function(data,
9494
bad_rows <- unique(bad_rows)
9595
tmp_report <- data.frame(idx = bad_rows,
9696
ids = data[[target_columns]][bad_rows])
97-
bad_rows <- paste(bad_rows, sep = ", ")
97+
bad_rows <- toString(bad_rows)
9898
warning("Detected incorrect subject ids at lines: ", bad_rows,
9999
"\nUse the correct_subject_ids() function to adjust them.\n",
100100
call. = FALSE)

inst/CITATION

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ bibentry(
1919
title = paste0(meta$Package, ": ", gsub("[[:space:]]+", " ", meta$Title)),
2020
author = author,
2121
year = date,
22-
url = meta$URL
22+
url = paste0(meta$URL, "/")
2323
)

man/to_numeric_convert.Rd

-19
This file was deleted.

tests/testthat/test-clean_data.R

+5-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ standardize_subject_ids <- list(target_columns = "study_id",
3535
nchar = 7L)
3636
to_numeric <- list(target_columns = "sex",
3737
lang = "en")
38+
check_date_sequence <- list(
39+
target_columns = c("date_first_pcr_positive_test", "date.of.admission")
40+
)
3841
params <- list(
3942
standardize_column_names = standardize_col_names,
4043
remove_constants = list(cutoff = 1.0),
@@ -43,7 +46,8 @@ params <- list(
4346
standardize_dates = standardize_dates,
4447
standardize_subject_ids = standardize_subject_ids,
4548
to_numeric = to_numeric,
46-
dictionary = test_dictionary
49+
dictionary = test_dictionary,
50+
check_date_sequence = check_date_sequence
4751
)
4852

4953
test_that("clean_data works as expected", {

tests/testthat/test-standardize_subject_ids.R

+10
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ test_that("check_subject_ids sends a message when duplicated IDs are found", {
100100
)
101101
})
102102

103+
test_that("check_subject_ids when the id column is numeric", {
104+
data <- readRDS(system.file("extdata", "test_df.RDS", package = "cleanepi"))
105+
data[["case_id"]] <- seq_len(nrow(data))
106+
dat <- check_subject_ids(data = data,
107+
target_columns = "case_id")
108+
expect_s3_class(dat, "data.frame")
109+
expect_false(identical(data, dat))
110+
expect_true(nrow(data) == nrow(dat))
111+
})
112+
103113
data <- readRDS(system.file("extdata", "test_df.RDS", package = "cleanepi"))
104114
test_that("check_subject_ids works when relying on the nchar argument", {
105115
dat <- check_subject_ids(data = data,

tests/testthat/test-utils.R

+14
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ test_that("get_target_column_names works with
2727
expect_identical(target_columns, c("dateOfBirth", "sex"))
2828
})
2929

30+
test_that("get_target_column_names works with
31+
target_columns as a vector of numeric values", {
32+
target_columns <- get_target_column_names(
33+
data = readRDS(system.file("extdata",
34+
"test_df.RDS",
35+
package = "cleanepi")),
36+
target_columns = c(6L, 8L),
37+
cols = NULL
38+
)
39+
expect_type(target_columns, "character")
40+
expect_length(target_columns, 2L)
41+
expect_identical(target_columns, c("dateOfBirth", "sex"))
42+
})
43+
3044
test_that("get_target_column_names works with target_columns and cols", {
3145
target_columns <- get_target_column_names(
3246
data = readRDS(system.file("extdata",

0 commit comments

Comments
 (0)