-
Notifications
You must be signed in to change notification settings - Fork 48
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
lares::holidays produces empty frame #45
Comments
Hi @Patrikios thanks for reporting this. Would you mind trying again? I've just tested it and it seems it's working. Maybe that was a temporary issue with your/the site's connection? |
Thnx for response. As I suspected firewall I tried as well installing the package locally and it as well produces empty frame. |
Must be a connection issue then. Does it provide any warning or error? Can you try updating to the latest dev version to see if that helps? Lastly, you could try using |
I debuged a bit on my maschine. The fisrt part incl. the loop runs OK: countries = "Venezuela"
years = year(Sys.Date())
results <- NULL
year <- year(Sys.Date())
years <- years[years %in% ((year - 5):(year + 5))]
combs <- expand.grid(years, countries) %>% dplyr::rename(year = "Var1", country = "Var2")
for (i in seq_len(nrow(combs))) {
message(paste0(">>> Extracting ", combs$country[i], "'s holidays for ", combs$year[i]))
url <- paste0("https://www.timeanddate.com/holidays/", tolower(combs$country[i]), "/", combs$year[i])
holidays <- content(GET(url))
holidays <- holidays %>%
html_nodes(".table") %>%
html_table(fill = TRUE) %>%
data.frame(.) %>%
filter(!is.na(.data$Date))
holidays <- holidays[, -2]
colnames(holidays) <- c("Date", "Holiday", "Holiday.Type")
holidays$Date <- paste(holidays$Date, combs$year[i])
if (sum(grepl("de", holidays$Date)) > 0) {
holidays$Date <- gsub("de ", "", holidays$Date)
}
holidays <- holidays[-1, ]
first <- suppressWarnings(as.numeric(as.character(substr(holidays$Date, 1, 1))))
if (!is.na(first[1])) {
holidays$Date <- as.Date(holidays$Date, format = "%d %b %Y")
} else {
holidays$Date <- as.Date(holidays$Date, format = "%b %d %Y")
}
result <- data.frame(
holiday = holidays$Date,
holiday_name = holidays$Holiday,
holiday_type = holidays$Holiday.Type
) %>%
mutate(
national = grepl("National|Federal", holidays$Holiday.Type),
observance = grepl("Observance", holidays$Holiday.Type),
bank = grepl("Bank", holidays$Holiday.Type),
nonwork = grepl("Non-working", holidays$Holiday.Type),
season = grepl("Season", holidays$Holiday.Type),
hother = !grepl("National|Federal|Observance|Season", holidays$Holiday.Type)
) %>%
{
if (length(unique(countries)) > 1) {
mutate(., country = combs$country[i])
} else {
.
}
}
result$county <- combs$country[i]
results <- bind_rows(results, result)
} results in: results
holiday holiday_name holiday_type national observance bank nonwork season hother county
1 <NA> The Three Wise Men Day Observance FALSE TRUE FALSE FALSE FALSE FALSE Venezuela
2 <NA> The Three Wise Men Day Bank holiday FALSE FALSE TRUE FALSE FALSE TRUE Venezuela
3 <NA> Three Kings Day Holiday Bank holiday FALSE FALSE TRUE FALSE FALSE TRUE Venezuela
4 <NA> Divina Pastora Day Observance FALSE TRUE FALSE FALSE FALSE FALSE Venezuela
5 <NA> Carnival / Shrove Monday National holiday TRUE FALSE FALSE FALSE FALSE FALSE Venezuela
6 <NA> Carnival / Shrove Tuesday / Pancake Day National holiday TRUE FALSE FALSE FALSE FALSE FALSE Venezuela
7 <NA> Saint Joseph's Day Observance FALSE TRUE FALSE FALSE FALSE FALSE Venezuela
8 <NA> March Equinox Season FALSE FALSE FALSE FALSE TRUE FALSE Venezuela
9 <NA> Palm Sunday Observance, Christian FALSE TRUE FALSE FALSE FALSE FALSE Venezuela
10 <NA> Maundy Thursday National holiday, Christian TRUE FALSE FALSE FALSE FALSE FALSE Venezuela
11 <NA> Good Friday National holiday, Christian TRUE FALSE FALSE FALSE FALSE FALSE Venezuela
12 <NA> Easter Sunday Observance, Christian FALSE TRUE FALSE FALSE FALSE FALSE Venezuela
13 <NA> Declaration of Independence National holiday TRUE FALSE FALSE FALSE FALSE FALSE Venezuela
14 <NA> Labor Day / May Day National holiday TRUE FALSE FALSE FALSE FALSE FALSE Venezuela
15 <NA> Ascension Day Observance FALSE TRUE FALSE FALSE FALSE FALSE Venezuela
16 <NA> Ascension Day Holiday Bank holiday FALSE FALSE TRUE FALSE FALSE TRUE Venezuela
17 <NA> Corpus Christi Observance FALSE TRUE FALSE FALSE FALSE FALSE Venezuela
18 <NA> Corpus Christi Holiday Bank holiday FALSE FALSE TRUE FALSE FALSE TRUE Venezuela
19 <NA> St Anthony's Day Observance FALSE TRUE FALSE FALSE FALSE FALSE Venezuela
20 <NA> St Anthony's Day Holiday Bank holiday FALSE FALSE TRUE FALSE FALSE TRUE Venezuela
21 <NA> June Solstice Season FALSE FALSE FALSE FALSE TRUE FALSE Venezuela
22 <NA> Carabobo Battle National holiday TRUE FALSE FALSE FALSE FALSE FALSE Venezuela
23 <NA> Saint Peter and Saint Paul Observance FALSE TRUE FALSE FALSE FALSE FALSE Venezuela
24 <NA> Saint Peter and Saint Paul Holiday Bank holiday FALSE FALSE TRUE FALSE FALSE TRUE Venezuela
25 <NA> Independence Day National holiday TRUE FALSE FALSE FALSE FALSE FALSE Venezuela
26 <NA> Simón Bolívar's Birthday National holiday TRUE FALSE FALSE FALSE FALSE FALSE Venezuela
27 <NA> Flag's Day Observance FALSE TRUE FALSE FALSE FALSE FALSE Venezuela
28 <NA> National Guard's Day Observance FALSE TRUE FALSE FALSE FALSE FALSE Venezuela
29 <NA> Assumption of Mary Holiday Bank holiday FALSE FALSE TRUE FALSE FALSE TRUE Venezuela
30 <NA> Assumption of Mary Observance FALSE TRUE FALSE FALSE FALSE FALSE Venezuela
31 <NA> Our Lady of Coromoto Bank holiday FALSE FALSE TRUE FALSE FALSE TRUE Venezuela
32 <NA> September Equinox Season FALSE FALSE FALSE FALSE TRUE FALSE Venezuela
33 <NA> Day of Indigenous Resistance National holiday TRUE FALSE FALSE FALSE FALSE FALSE Venezuela
34 <NA> Dr. José Gregorio Hernández Day Observance FALSE TRUE FALSE FALSE FALSE FALSE Venezuela
35 <NA> Holiday for Dr. José Gregorio Hernández Day Bank holiday FALSE FALSE TRUE FALSE FALSE TRUE Venezuela
36 <NA> All Saints Day Observance FALSE TRUE FALSE FALSE FALSE FALSE Venezuela
37 <NA> All Souls Day Observance FALSE TRUE FALSE FALSE FALSE FALSE Venezuela
38 <NA> All Saints Day Holiday Bank holiday FALSE FALSE TRUE FALSE FALSE TRUE Venezuela
39 <NA> Day of the Virgin of the Rosary of Chiquinquirá Observance FALSE TRUE FALSE FALSE FALSE FALSE Venezuela
40 <NA> Aviation Day Observance FALSE TRUE FALSE FALSE FALSE FALSE Venezuela
41 <NA> Feast of the Immaculate Conception Observance FALSE TRUE FALSE FALSE FALSE FALSE Venezuela
42 <NA> Holiday for Feast of the Immaculate Conception Bank holiday FALSE FALSE TRUE FALSE FALSE TRUE Venezuela
43 <NA> December Solstice Season FALSE FALSE FALSE FALSE TRUE FALSE Venezuela
44 <NA> Christmas Eve National holiday, Christian TRUE FALSE FALSE FALSE FALSE FALSE Venezuela
45 <NA> Christmas Day National holiday, Christian TRUE FALSE FALSE FALSE FALSE FALSE Venezuela
46 <NA> New Year's Eve National holiday TRUE FALSE FALSE FALSE FALSE FALSE Venezuela Then comes: results %>%
filter(!is.na(.data$holiday)) %>%
cleanNames() %>%
as_tibble() and voila: results
# A tibble: 0 × 10
# ℹ 10 variables: holiday <date>, holiday_name <chr>, holiday_type <chr>, national <lgl>, observance <lgl>, bank <lgl>, nonwork <lgl>, season <lgl>, hother <lgl>, county <fct> |
So the problem is here:
trying to parse format:
could be rather, more dynamic:
But the problem is there. I wonder, does the table extraction from the HTTP response depend on my German local? If so then |
There is still isuues, aas it involves formats that are not german local like the formats: |
Hi @Patrikios thanks for taking the time to check this. I've just deployed your suggestion on using |
Hi, |
Issued a pull request, take a look please. The best way to solve the problem I think is to set header poperly touse en language in the response. |
I've merged with main. Thanks for the improvement. |
Yes of course. Can u give excerpt of the table holidays just before running the try catch part? Are the dates in expected English format? Otherwise on my windows and Debian 10 Maschinen ran okay, hence I cannot debug locally here unfortunately. |
I run the basic example:
Gives back empty data.frame, simmilar to other countries I tried.
Session Info:
The text was updated successfully, but these errors were encountered: