0

In timetk ,the result of function tk_make_weekend_sequence show nothing . Anyone can help? Thanks!

library(timetk)

weekends <- tk_make_weekend_sequence(
  start_date = "2017-01-01",
  end_date   = "2017-12-31"
)

weekends

enter image description here

anderwyang
  • 1,801
  • 4
  • 18
  • 1
    This works fine for me, maybe you should update the package, or it may be linked to your locale? Try to convert to date format with `as.Date` otherwise. – Maël Mar 11 '22 at 09:47

1 Answers1

1

To fix this you need to set an English environment for the "LC_TIME"

Sys.setlocale("LC_TIME", "English")

weekends <- tk_make_weekend_sequence(
  start_date = "2017-01-01",
  end_date   = "2017-12-31"
)

weekends

Function tk_make_weekend_sequence uses a lubridate::wday function which work with your local language settings.

ret_tbl <- tibble::tibble(date_sequence = date_sequence) %>%
    dplyr::mutate(weekday = lubridate::wday(date_sequence, label = TRUE)) %>%
    dplyr::filter((weekday == "Sat" | weekday == "Sun"))

The problem is triggered by the filter in the last row. If you don't change "LC_TIME", weekday will be the abbreviation of the day name in your native language.

Lstat
  • 1,450
  • 1
  • 12
  • 18