I've got a problem where complete() fails if I call my variable "d" but not if I call it "y". I'm flummoxed by this. Here's a reprex (you can see if works if I keep the name the same, and if I call it "y", but not if I call it "d"):
library(tidyverse)
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:base':
#>
#> date
t <- tibble::tribble(
~id, ~YearStart,
1L, "01/01/2014",
1L, "01/01/2015",
1L, "01/01/2017",
2L, "01/01/2018",
2L, "01/01/2020"
)
t %>%
mutate(YearStart = dmy(YearStart)) %>%
complete(YearStart = seq(min(YearStart), max(YearStart), by = "year"), nesting(id))
#> # A tibble: 14 x 2
#> YearStart id
#> <date> <int>
#> 1 2014-01-01 1
#> 2 2014-01-01 2
#> 3 2015-01-01 1
#> 4 2015-01-01 2
#> 5 2016-01-01 1
#> 6 2016-01-01 2
#> 7 2017-01-01 1
#> 8 2017-01-01 2
#> 9 2018-01-01 1
#> 10 2018-01-01 2
#> 11 2019-01-01 1
#> 12 2019-01-01 2
#> 13 2020-01-01 1
#> 14 2020-01-01 2
t %>%
mutate(d = dmy(YearStart)) %>%
complete(d = seq(min(d), max(d), by = "year"), nesting(id))
#> Error in seq(min(d), max(d), by = "year"): object 'd' not found
t %>%
mutate(y = dmy(YearStart)) %>%
complete(y = seq(min(y), max(y), by = "year"), nesting(id))
#> # A tibble: 14 x 3
#> y id YearStart
#> <date> <int> <chr>
#> 1 2014-01-01 1 01/01/2014
#> 2 2014-01-01 2 <NA>
#> 3 2015-01-01 1 01/01/2015
#> 4 2015-01-01 2 <NA>
#> 5 2016-01-01 1 <NA>
#> 6 2016-01-01 2 <NA>
#> 7 2017-01-01 1 01/01/2017
#> 8 2017-01-01 2 <NA>
#> 9 2018-01-01 1 <NA>
#> 10 2018-01-01 2 01/01/2018
#> 11 2019-01-01 1 <NA>
#> 12 2019-01-01 2 <NA>
#> 13 2020-01-01 1 <NA>
#> 14 2020-01-01 2 01/01/2020
Created on 2020-05-26 by the reprex package (v0.3.0)