Skip to content
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

Start date End date #26

Open
zx8754 opened this issue Oct 28, 2021 · 1 comment
Open

Start date End date #26

zx8754 opened this issue Oct 28, 2021 · 1 comment

Comments

@zx8754
Copy link

zx8754 commented Oct 28, 2021

There is already dob, date_stamp, and we could use these to get start and end dates, e.g.:

set.seed(1)
r_data_frame(
  n = 5,
  dob(name = "date_start")) %>% 
  mutate(date_end = date_start + runif(n(), 1, 100))

# # A tibble: 5 x 2
#   date_start date_end  
#   <date>     <date>    
# 1 2007-04-20 2007-06-01
# 2 2007-03-23 2007-06-16
# 3 2008-06-06 2008-07-29
# 4 2007-02-21 2007-04-17
# 5 2008-05-08 2008-07-31

Could we have a dedicated function that would create start and end date, where obviously date_end can't be before the date_start?

Or maybe even better, let date_stamp accept column name for start=, like below:

r_data_frame(
  n = 5,
  dob(name = "date_start")) %>% 
  mutate(date_end = date_stamp(start = date_start))
# Error in seq(start, length = k, by = by) : object 'date_start' not found
@hadley
Copy link

hadley commented Oct 3, 2022

Did you mean this?

library(wakefield)

r_data_frame(
  n = 5,
  dob(name = "date_start"),
  date_stamp(start = date_start)
)
#> Error in seq(start, length = k, by = by): object 'date_start' not found

Created on 2022-10-03 with reprex v2.0.2

If so, this could be made to work by having r_data_frame() compute each column iteratively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants