Error: Can't retrieve sheet in position 42, only 41 sheet(s) found.

jpinfect_get_confirmed(years = 2010, type = "sex", dest_dir = temp_dir)
test_that(".jpinfect_read_excel imports Excel file correctly", {
skip_if_not(file.exists(temp_file), "Test skipped: Unable to download the test Excel file.")
result <- .jpinfect_read_excel(file_path = temp_file, year = 2010),
expect_true(all(c("prefecture", "year", "week") %in% colnames(result)))
test_that(".jpinfect_read_excel handles errors appropriately", {
expect_error(.jpinfect_read_excel(file_path = unsupported_file), "Unsupported file format")
expect_error(.jpinfect_read_excel(), "The 'file_path' argument is missing.")
expect_error(.jpinfect_read_excel(file_path = NULL), "The 'file_path' is empty.")
expect_error(.jpinfect_read_excel(file_path = ""), "The 'file_path' is empty.")
test_that(".col_rename processes column names correctly", {
`Pandemic influenza (A/H1N1)` = c(10, 11, 12),
c("Example I", "Example (", "Pandemic influenza (A/H1N1)"))
test_that(".col_rename handles repetition and empty datasets", {
mock_dataset <- data.frame(malaria = c(1, 2, 3), dengue = c(4, 5, 6))
expect_equal(.col_rename(mock_dataset, rep_each = 2), c("malaria", "malaria", "dengue", "dengue"))
expect_equal(.col_rename(mock_empty, rep_each = 1), character(0))
jpinfect_get_confirmed(years = c(1999, 2014), type = "sex", dest_dir = temp_dir)
jpinfect_get_confirmed(years = c(2014, 2017), type = "place", dest_dir = temp_dir)
test_that(".jpinfect_read_excels processes data correctly", {
result_sex <- .jpinfect_read_excels(type = "sex", directory = temp_dir)
expect_true(all(c("year", "week", "prefecture") %in% colnames(result_sex)))
result_place <- .jpinfect_read_excels(type = "place", directory = temp_dir)
expect_true(all(c("year", "week", "prefecture") %in% colnames(result_place)))
test_that(".jpinfect_read_excels handles invalid inputs", {
expect_error(.jpinfect_read_excels(type = "invalid", directory = temp_dir), "type must be either \"sex\" or \"place\"")
expect_error(.jpinfect_read_excels(type = "sex", directory = empty_dir), "Cannot found dataset")
test_that(".jpinfect_read_excels displays correct logs", {
logs <- capture.output(.jpinfect_read_excels(type = "sex", directory = temp_dir))
expect_true(any(grepl("Please enjoy a cup of Japanese tea!", logs)))
"Invalid path: must be either a file or directory"
"The 'type' argument is required when processing a directory and must be specified as either 'sex' or 'place'."
jpinfect_read_confirmed(path = temp_dir, type = "invalid"),
"Invalid 'type' argument: must be either 'sex' or 'place'."
test_that("jpinfect_read_confirmed processes files and directories correctly", {
.jpinfect_read_excel = function(file_path, ...) {
result <- jpinfect_read_confirmed(path = temp_file, type = "sex")
.jpinfect_read_excels = function(type, directory, ...) {
result <- jpinfect_read_confirmed(path = temp_dir, type = "place")