Derive end of the week date in r

# Load necessary library
library(lubridate)

# Get current date
current_date <- Sys.Date()

# Identify the current day of the week
current_day <- weekdays(current_date)

# Calculate the number of days remaining until the end of the week (Sunday)
days_until_end_of_week <- ifelse(current_day == "Sunday", 0, match(current_day, c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")))

# Derive the end of the week date
end_of_week_date <- current_date + days_until_end_of_week + (7 - days_until_end_of_week)

# Print the end of the week date
print(end_of_week_date)