Warning message on mutate() its not working

# Packages ----------------------------------------------------------------

pacman::p_load(
  rio,          # for importing data
  here,         # for file paths
  janitor,      # for data cleaning
  tidyverse,    # for data management
  reprex,       #minimal repr example
  datapasta     #sample data
)


# Import Data -------------------------------------------------------------

surv_raw <- data.frame(
  stringsAsFactors = FALSE,
  check.names = FALSE,
  case_id = c("694928","86340d","92d002",
              "544bd1","6056ba","eb5aeb","e64e04","5a65bb","2ae019",
              "7ca4c0"),
  `onset date` = c("11/9/2014","10/30/2014",
                   "8/16/2014","8/29/2014","10/20/2014","10/28/2014",
                   "10/6/2014","9/21/2014","5/6/2014","9/29/2014"),
  `date of report` = c("11/9/2014","10/31/2014",
                       "8/20/2014","8/30/2014","10/21/2014","11/1/2014",
                       "10/10/2014","9/22/2014","5/11/2014","9/30/2014")
)



# Cleaning Data -----------------------------------------------------------

surv <- surv_raw %>% 
  clean_names() %>% 
  
  select(case_id, onset_date, date_of_report) %>% 
  mutate(onset_date = ymd(onset_date)) %>% 
  mutate(date_of_report = ymd(onset_date))
#> Warning: There was 1 warning in `mutate()`.
#> ℹ In argument: `onset_date = ymd(onset_date)`.
#> Caused by warning:
#> ! All formats failed to parse. No formats found.

print(surv)
#>    case_id onset_date date_of_report
#> 1   694928       <NA>           <NA>
#> 2   86340d       <NA>           <NA>
#> 3   92d002       <NA>           <NA>
#> 4   544bd1       <NA>           <NA>
#> 5   6056ba       <NA>           <NA>
#> 6   eb5aeb       <NA>           <NA>
#> 7   e64e04       <NA>           <NA>
#> 8   5a65bb       <NA>           <NA>
#> 9   2ae019       <NA>           <NA>
#> 10  7ca4c0       <NA>           <NA>

Created on 2024-08-09 with reprex v2.1.1

Session info
sessionInfo()
#> R version 4.4.1 (2024-06-14 ucrt)
#> Platform: x86_64-w64-mingw32/x64
#> Running under: Windows 11 x64 (build 22631)
#> 
#> Matrix products: default
#> 
#> 
#> locale:
#> [1] LC_COLLATE=English_Philippines.utf8  LC_CTYPE=English_Philippines.utf8   
#> [3] LC_MONETARY=English_Philippines.utf8 LC_NUMERIC=C                        
#> [5] LC_TIME=English_Philippines.utf8    
#> 
#> time zone: Asia/Manila
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#>  [1] datapasta_3.1.0 reprex_2.1.1    lubridate_1.9.3 forcats_1.0.0  
#>  [5] stringr_1.5.1   dplyr_1.1.4     purrr_1.0.2     readr_2.1.5    
#>  [9] tidyr_1.3.1     tibble_3.2.1    ggplot2_3.5.1   tidyverse_2.0.0
#> [13] janitor_2.2.0   here_1.0.1      rio_1.2.1      
#> 
#> loaded via a namespace (and not attached):
#>  [1] utf8_1.2.4        generics_0.1.3    stringi_1.8.4     hms_1.1.3        
#>  [5] digest_0.6.36     magrittr_2.0.3    evaluate_0.24.0   grid_4.4.1       
#>  [9] timechange_0.3.0  fastmap_1.2.0     rprojroot_2.0.4   fansi_1.0.6      
#> [13] scales_1.3.0      cli_3.6.3         rlang_1.1.4       munsell_0.5.1    
#> [17] withr_3.0.1       yaml_2.3.10       tools_4.4.1       tzdb_0.4.0       
#> [21] colorspace_2.1-1  pacman_0.5.1      vctrs_0.6.5       R6_2.5.1         
#> [25] lifecycle_1.0.4   snakecase_0.11.1  fs_1.6.4          pkgconfig_2.0.3  
#> [29] pillar_1.9.0      gtable_0.3.5      glue_1.7.0        xfun_0.46        
#> [33] tidyselect_1.2.1  rstudioapi_0.16.0 knitr_1.48        htmltools_0.5.8.1
#> [37] rmarkdown_2.27    compiler_4.4.1

Hello,

Your dates are formatted as mm/dd/YYYY but you used the ymd function from lubridate. You need to use the mdy function instead since this is the format of your dates. Additionally, in your second mutate statement, you defined date_of_report using onset_date which is likely not what you intended.

For example:

# loading packages
library(tidyverse)
library(janitor)
#> 
#> Attaching package: 'janitor'
#> The following objects are masked from 'package:stats':
#> 
#>     chisq.test, fisher.test

# creating fake data
surv_raw <- data.frame(
    stringsAsFactors = FALSE,
    check.names = FALSE,
    case_id = c(
        "694928",
        "86340d",
        "92d002",
        "544bd1",
        "6056ba",
        "eb5aeb",
        "e64e04",
        "5a65bb",
        "2ae019",
        "7ca4c0"
    ),
    `onset date` = c(
        "11/9/2014",
        "10/30/2014",
        "8/16/2014",
        "8/29/2014",
        "10/20/2014",
        "10/28/2014",
        "10/6/2014",
        "9/21/2014",
        "5/6/2014",
        "9/29/2014"
    ),
    `date of report` = c(
        "11/9/2014",
        "10/31/2014",
        "8/20/2014",
        "8/30/2014",
        "10/21/2014",
        "11/1/2014",
        "10/10/2014",
        "9/22/2014",
        "5/11/2014",
        "9/30/2014"
    )
) |>
    as_tibble()

# cleaning data
surv_clean <- surv_raw |>
    clean_names() |>
    select(case_id, onset_date, date_of_report) |>
    mutate(onset_date = mdy(onset_date),
                 date_of_report = mdy(date_of_report))

surv_clean
#> # A tibble: 10 × 3
#>    case_id onset_date date_of_report
#>    <chr>   <date>     <date>        
#>  1 694928  2014-11-09 2014-11-09    
#>  2 86340d  2014-10-30 2014-10-31    
#>  3 92d002  2014-08-16 2014-08-20    
#>  4 544bd1  2014-08-29 2014-08-30    
#>  5 6056ba  2014-10-20 2014-10-21    
#>  6 eb5aeb  2014-10-28 2014-11-01    
#>  7 e64e04  2014-10-06 2014-10-10    
#>  8 5a65bb  2014-09-21 2014-09-22    
#>  9 2ae019  2014-05-06 2014-05-11    
#> 10 7ca4c0  2014-09-29 2014-09-30

Created on 2024-08-09 with reprex v2.1.1

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.4.1 (2024-06-14)
#>  os       macOS Sonoma 14.5
#>  system   x86_64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       America/Toronto
#>  date     2024-08-09
#>  pandoc   3.1.11 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/x86_64/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  cli           3.6.3   2024-06-21 [1] RSPM (R 4.4.0)
#>  colorspace    2.1-0   2023-01-23 [1] RSPM (R 4.4.0)
#>  digest        0.6.36  2024-06-23 [1] RSPM (R 4.4.0)
#>  dplyr       * 1.1.4   2023-11-17 [1] RSPM (R 4.4.0)
#>  evaluate      0.24.0  2024-06-10 [1] RSPM (R 4.4.0)
#>  fansi         1.0.6   2023-12-08 [1] RSPM (R 4.4.0)
#>  fastmap       1.2.0   2024-05-15 [1] RSPM (R 4.4.0)
#>  forcats     * 1.0.0   2023-01-29 [1] RSPM (R 4.4.0)
#>  fs            1.6.4   2024-04-25 [1] RSPM (R 4.4.0)
#>  generics      0.1.3   2022-07-05 [1] RSPM (R 4.4.0)
#>  ggplot2     * 3.5.1   2024-04-23 [1] RSPM (R 4.4.0)
#>  glue          1.7.0   2024-01-09 [1] RSPM (R 4.4.0)
#>  gtable        0.3.5   2024-04-22 [1] RSPM (R 4.4.0)
#>  hms           1.1.3   2023-03-21 [1] RSPM (R 4.4.0)
#>  htmltools     0.5.8.1 2024-04-04 [1] RSPM (R 4.4.0)
#>  janitor     * 2.2.0   2023-02-02 [1] CRAN (R 4.4.0)
#>  knitr         1.48    2024-07-07 [1] RSPM (R 4.4.0)
#>  lifecycle     1.0.4   2023-11-07 [1] RSPM (R 4.4.0)
#>  lubridate   * 1.9.3   2023-09-27 [1] RSPM (R 4.4.0)
#>  magrittr      2.0.3   2022-03-30 [1] RSPM (R 4.4.0)
#>  munsell       0.5.1   2024-04-01 [1] RSPM (R 4.4.0)
#>  pillar        1.9.0   2023-03-22 [1] RSPM (R 4.4.0)
#>  pkgconfig     2.0.3   2019-09-22 [1] RSPM (R 4.4.0)
#>  purrr       * 1.0.2   2023-08-10 [1] RSPM (R 4.4.0)
#>  R6            2.5.1   2021-08-19 [1] RSPM (R 4.4.0)
#>  readr       * 2.1.5   2024-01-10 [1] RSPM (R 4.4.0)
#>  reprex        2.1.1   2024-07-06 [1] RSPM (R 4.4.0)
#>  rlang         1.1.4   2024-06-04 [1] RSPM (R 4.4.0)
#>  rmarkdown     2.27    2024-05-17 [1] RSPM (R 4.4.0)
#>  rstudioapi    0.16.0  2024-03-24 [1] RSPM (R 4.4.0)
#>  scales        1.3.0   2023-11-28 [1] RSPM (R 4.4.0)
#>  sessioninfo   1.2.2   2021-12-06 [1] RSPM (R 4.4.0)
#>  snakecase     0.11.1  2023-08-27 [1] CRAN (R 4.4.0)
#>  stringi       1.8.4   2024-05-06 [1] RSPM (R 4.4.0)
#>  stringr     * 1.5.1   2023-11-14 [1] RSPM (R 4.4.0)
#>  tibble      * 3.2.1   2023-03-20 [1] RSPM (R 4.4.0)
#>  tidyr       * 1.3.1   2024-01-24 [1] RSPM (R 4.4.0)
#>  tidyselect    1.2.1   2024-03-11 [1] RSPM (R 4.4.0)
#>  tidyverse   * 2.0.0   2023-02-22 [1] RSPM (R 4.4.0)
#>  timechange    0.3.0   2024-01-18 [1] RSPM (R 4.4.0)
#>  tzdb          0.4.0   2023-05-12 [1] RSPM (R 4.4.0)
#>  utf8          1.2.4   2023-10-22 [1] RSPM (R 4.4.0)
#>  vctrs         0.6.5   2023-12-01 [1] RSPM (R 4.4.0)
#>  withr         3.0.0   2024-01-16 [1] RSPM (R 4.4.0)
#>  xfun          0.45    2024-06-16 [1] RSPM (R 4.4.0)
#>  yaml          2.3.9   2024-07-05 [1] RSPM (R 4.4.0)
#> 
#>  [1] /Users/timothychisamore/Library/R/x86_64/4.4/library
#>  [2] /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

All the best,

Tim