# \donttest{
# Create a temporary folder for the example
# Ensure the temporary folder is cleaned up after the example
if (reticulate::py_module_available("pytrends")) {
params <- initialize_request_trends(
keyword = "Coronavirus disease 2019",
topic = "/g/11j2cc_qll",
folder_name = file.path(tempdir(), "test_folder"),
start_date = "2024-05-01",
end_date = "2024-05-03",
data_format = "daily"
)
on.exit(unlink("test_folder", recursive = TRUE))
# Run the time_series function with the parameters
tryCatch({
time_series(params, reference_geo_code = "US-CA")
}, pytrends.exceptions.TooManyRequestsError = function(e) {
message("Too many requests error: ", conditionMessage(e))
})
} else {
message("The 'pytrends' module is not available.
Please install it by running install_pytrendslongitudinalr()")
}
# }
Run the code above in your browser using DataLab