-
Notifications
You must be signed in to change notification settings - Fork 10
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
Eurostat issue #55
Comments
Many thanks for the reproducible example @serkor1. I don't have any time to look at this right now, do you have any ideas for a fix? |
Hi @Robinlovelace - I actually don't as I am new to the package. But I would be happy to browse and explore and possibly post a fix during the weekend to assist the development, if you want! |
That would be amazing, any questions you have just let me know, also cc package co-author @layik 🙏 |
Actually, it's a trivial fix it seems. See the code below, You are assigning x_df[date_cols] <- lapply(x_df[date_cols], ic_date) Full solution: ic_dataframe <- function(x) {
if(methods::is(object = x, class2 = "data.frame")) {
return(x)
}
stopifnot(methods::is(object = x, class2 = "character") | methods::is(object = x, class2 = "list"))
if(methods::is(object = x, class2 = "character")) {
x_list <- ic_list(x)
} else if(methods::is(object = x, class2 = "list")) {
x_list <- x
}
x_list_named <- lapply(x_list, function(x) {
ic_vector(x)
})
x_df <- ic_bind_list(x_list_named)
date_cols <- grepl(pattern = "VALUE=DATE", x = names(x_df))
if(any(date_cols)) {
x_df[date_cols] <- lapply(x_df[date_cols], ic_date)
}
datetime_cols <- names(x_df) %in% c("DTSTART", "DTEND")
if(any(datetime_cols)) {
x_df[datetime_cols] <- lapply(x_df[datetime_cols], ic_datetime)
}
# names(x_df) <- gsub(pattern = ".VALUE.DATE", replacement = "", names(x_df))
x_df
} Showcase the solution # library
rm(list = ls()); gc(); devtools::load_all()
# read ical
ical <- readLines(
"https://ec.europa.eu/eurostat/o/calendars/eventsIcal?theme=2&category=2"
)
# convert to data.frame
DT <- ic_dataframe(
ical
)
# check dates
head(DT$`DTSTART;VALUE=DATE`)
# > "2023-01-06" "2023-01-06" "2023-01-10" "2023-01-11" "2023-01-11" "2023-01-18" Which is what we want. I have run Edit: Assuming that the helper functions works without any issues I believe this solution is robust. I have tested this by adding a few more date variables after locating the offending lines of code! |
Great work, super simple fix, thank you so much! So this line and perhaps one other need to change? Line 39 in bfd95e0
You should be able to edit the file and put in a PR here: ... |
Yes, both needs to be changed. I didn't want to do a PR for such a trivial fix! But I'll do one later this evening, unless you wan't to fix it right now 😃 Great package by the way, really love it! |
Awesome! Yes, will await your input, as a learning experience. Your idea so will be good to have your name on the fix 👍 |
Hi,
I have a slight issue with parsing calendar data from Eurostat using
ic_dataframe
and/oric_read
. This issue only arises when I use {calendar}, there is no issue when using {ical}.The issue is as follows; the dates are not parsing correctly when using
ic_dataframe
oric_read
, but this is not an issue when usingical::ical_parse_df
. The issue can be mitigated, however, by using a mix ofic_list
,lapply
anddo.call
. See the MWE below,Created on 2024-08-07 with reprex v2.1.0
Session info
The text was updated successfully, but these errors were encountered: