Stack Exchange
How to resolve the problem with "function and object not found" while fetching the OECD data using R?
I am trying to fetch some code from webpage https://fgeerolf.com/data/oecd/ULC_QUA.html#labour_income_share_(real_ulc)_(total_economy) and replicate the code, but I encountered the error message "function and object not found".
The code given is:
ULC_QUA %>%
  filter(MEASURE == "IXOBTE",
         SUBJECT == "ULQBBU99",
         LOCATION == "DEU") %>%
  left_join(ULC_QUA_var$SECTOR, by = c("SECTOR" = "id")) %>%
  rename(SECTOR_desc = label) %>%
  year_to_date %>%
  arrange(SECTOR_desc) %>%
  ggplot() + 
  geom_line(aes(x = date, y = obsValue, color = SECTOR_desc, linetype = SECTOR_desc)) +
  scale_color_manual(values = viridis(9)[1:8]) +
  theme_minimal() +
  scale_x_date(breaks = seq(1920, 2025, 2) %>% paste0("-01-01") %>% as.Date,
               labels = date_format("%y")) +
  theme(legend.position = c(0.8, 0.3),
        legend.title = element_blank()) +
  scale_y_continuous(breaks = seq(0, 200, 10)) +
  ylab("Labour Income Share (Real ULC) (Total Economy)") + xlab("")


And I got
Error in year_to_date(.) : could not find function "year_to_date"
Eventually I want to generate the following plot:

First of all, I think I need to read the original data from the source but I don't know the location and how to import the data. Is there anyway I can replicate the plot without any further information?
Any help would be much appreciated!

Where does your code come from? I searched for a function named year_to_date on rdocumentation.org, which indexes all the R packages on CRAN, and it can't find a function with that name. Maybe wherever you got the code also provides a definition?

I already put the address in the question above: https://fgeerolf.com/data/oecd/ULC_QUA.html#labour_income_share_(real_ulc)_(total_economy)

Since I don't know the original data source, object ULC_QUA, MEASURE, SUBJECT, LOCATION cannot be found either. I am still wondering if there could be a way to replicate at this point or simply is it impossible?

Ah, I didn't see that there were "code" buttons to show the code on that page. Yeah, the year_to_date function isn't standard, so you would have to figure out what it does and write a replacement. Perhaps a cumulative sum of numeric columns, grouped by non-numeric columns? Poking around the site, this looks like the data source.

Yeah, I agree. Maybe I should post a new question after digging in the code and data source since I need to recode some of the original codes. Thanks.
