I was working to clean my data as training but get error as the variable (onset_date) was not found

# install and load packages
pacman::p_load(
  rio,          # for importing data
  here,         # for locating files
  skimr,        # for reviewing the data
  janitor,      # for data cleaning  
  epikit,       # creating age categories
  gtsummary,    # creating tables  
  scales,       # percents in tables  
  flextable,    # for making pretty tables
  tidyverse,    # for data management and visualization
  datapasta,
  reprex
  )

# import data
surv_raw <- import(here("data", "raw", "surveillance_linelist_20141201.csv"))
#> Error: No such file: C:/Users/or0267951/AppData/Local/Temp/Rtmpesgtrp/reprex-51507c717448-awake-topi/data/raw/surveillance_linelist_20141201.csv


surv <- surv_raw %>% 
  
  # automatically clean column names
  clean_names() %>% 
  
  # manually clean column names   
  rename(
    date_onset = onset_date,
    date_report = date_of_report,
    district_res = adm3_name_res,
    district_det = adm3_name_det)%>%
  
  # remove unnecessary column
  select(-row_num) 
#> Error in eval(expr, envir, enclos): object 'surv_raw' not found


demo_data <- surv%>%
  head(10) %>%
  select(case_id,date_onset,sex)# keep only first 10 rows
#> Error in eval(expr, envir, enclos): object 'surv' not found


linelist_demo<-data.frame(
  stringsAsFactors = FALSE,
  case_id = c("694928","86340d","92d002",
              "544bd1","6056ba","eb5aeb","e64e04","5a65bb","2ae019",
              "7ca4c0"),
  date_onset = 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"),
  sex = c("m", "f", "f", "f", "f", "f", "f", "m", "m", "m")
)

class(linelist_demo$onset_date)
#> [1] "NULL"

linelist_demo <- linelist_demo %>%
  mutate(onset_date = ymd(onset_date))
#> Error in `mutate()`:
#> ℹ In argument: `onset_date = ymd(onset_date)`.
#> Caused by error:
#> ! object 'onset_date' not found

class(linelist_demo$onset_date)
#> [1] "NULL"

range(linelist_demo$onset_date)
#> Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
#> Inf
#> Warning in max(x, na.rm = na.rm): no non-missing arguments to max; returning
#> -Inf
#> [1]  Inf -Inf
sessionInfo()
#> R version 4.3.0 (2023-04-21 ucrt)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19044)
#> 
#> Matrix products: default
#> 
#> 
#> locale:
#> [1] LC_COLLATE=English_United States.utf8 
#> [2] LC_CTYPE=English_United States.utf8   
#> [3] LC_MONETARY=English_United States.utf8
#> [4] LC_NUMERIC=C                          
#> [5] LC_TIME=English_United States.utf8    
#> 
#> time zone: America/Los_Angeles
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#>  [1] reprex_2.1.0    datapasta_3.1.0 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.4.4   tidyverse_2.0.0
#> [13] flextable_0.9.4 scales_1.3.0    gtsummary_1.7.2 epikit_0.1.6   
#> [17] janitor_2.2.0   skimr_2.1.5     here_1.0.1      rio_1.0.1      
#> 
#> loaded via a namespace (and not attached):
#>  [1] tidyselect_1.2.0        R.utils_2.12.3          fastmap_1.1.1          
#>  [4] fontquiver_0.2.1        pacman_0.5.1            promises_1.2.1         
#>  [7] broom.helpers_1.14.0    digest_0.6.34           timechange_0.3.0       
#> [10] mime_0.12               lifecycle_1.0.4         sf_1.0-15              
#> [13] gfonts_0.2.0            ellipsis_0.3.2          magrittr_2.0.3         
#> [16] compiler_4.3.0          rlang_1.1.3             tools_4.3.0            
#> [19] utf8_1.2.4              yaml_2.3.8              gt_0.10.1              
#> [22] data.table_1.14.10      knitr_1.45              askpass_1.2.0          
#> [25] classInt_0.4-10         curl_5.2.0              xml2_1.3.6             
#> [28] repr_1.1.6              KernSmooth_2.23-22      httpcode_0.3.0         
#> [31] withr_3.0.0             R.oo_1.26.0             grid_4.3.0             
#> [34] fansi_1.0.6             gdtools_0.3.5           xtable_1.8-4           
#> [37] e1071_1.7-14            colorspace_2.1-0        crul_1.4.0             
#> [40] cli_3.6.2               rmarkdown_2.25          crayon_1.5.2           
#> [43] ragg_1.2.7              generics_0.1.3          rstudioapi_0.15.0      
#> [46] tzdb_0.4.0              DBI_1.2.1               proxy_0.4-27           
#> [49] base64enc_0.1-3         vctrs_0.6.5             jsonlite_1.8.8         
#> [52] fontBitstreamVera_0.1.1 hms_1.1.3               systemfonts_1.0.5      
#> [55] units_0.8-5             glue_1.7.0              stringi_1.8.3          
#> [58] gtable_0.3.4            later_1.3.2             munsell_0.5.0          
#> [61] pillar_1.9.0            htmltools_0.5.7         openssl_2.1.1          
#> [64] R6_2.5.1                textshaping_0.3.7       rprojroot_2.0.4        
#> [67] evaluate_0.23           shiny_1.8.0             R.methodsS3_1.8.2      
#> [70] snakecase_0.11.1        fontLiberation_0.1.0    httpuv_1.6.14          
#> [73] class_7.3-22            zip_2.3.1               uuid_1.2-0             
#> [76] Rcpp_1.0.12             officer_0.6.4           xfun_0.41              
#> [79] fs_1.6.3   

Hi,

Please see the following thread for a solution to this problem: Exercise for R Training course: Unexpected NA value in date column - #2 by machupovirus

All the best,

Tim