Skip to contents

Assemble a chronogram skeleton from start and end dates, and a vector of participant IDs. For most circumstances, cg_assemble() is suggested (which calls chronogram_skeleton() and chronogram()). See assembly vignette.

Usage

chronogram_skeleton(
  ids = NULL,
  col_ids = column_name_for_ids,
  start_date = NULL,
  end_date = NULL,
  col_calendar_date = column_name_for_calendar_date
)

Arguments

ids

a vector of study, or participant IDs.

col_ids

to label the ID column. Default is column_name_for_ids (unquoted). Studies may use StudyID, StudyId, PID, etc.

start_date

the start date, in a format recognised by lubridate::dmy()

end_date

the end date, in a format recognised by lubridate::dmy()

col_calendar_date

to label the date column. Default is column_name_for_calendar_date (unquoted).

Value

A chronogram skeleton (class tbl_df, with extra attributes).

Examples

##-----------------------------------------------------------------
small_study <- chronogram_skeleton(
  ids = c(1, 2, 3),
  start_date = "01012020",
  end_date = "10102021"
)

## These examples fail ##------------------------------------------
## Duplicate dates, or dates lubridate::dmy() does not recognise ##
small_study <- try(
chronogram_skeleton(
  ids = c(1, 2, 3),
  start_date = c("01012020", "05012020"),
  end_date = "10102021")
)
#> Error in chronogram_skeleton(ids = c(1, 2, 3), start_date = c("01012020",  : 
#>   More than 1 start dates provided!
small_study <- try(
chronogram_skeleton(
  ids = c(1, 2, 3),
  start_date = c("01012020"),
  end_date = c("10102021", "20102020"))
)
#> Error in chronogram_skeleton(ids = c(1, 2, 3), start_date = c("01012020"),  : 
#>   More than 1 end dates provided!
small_study <- try(
chronogram_skeleton(
  ids = c(1, 2, 3),
  start_date = "20200101",
  end_date = "10102021")
)
#> Error in chronogram_skeleton(ids = c(1, 2, 3), start_date = "20200101",  : 
#>   Start date failed to parse! Provide in dmy format.
small_study <- try(
chronogram_skeleton(
  ids = c(1, 2, 3),
  start_date = "01012020",
  end_date = "20201010")
)
#> Error in chronogram_skeleton(ids = c(1, 2, 3), start_date = "01012020",  : 
#>   End date failed to parse! Provide in dmy format.

## Duplicate participant IDs are accepted, but give a warning ##
small_study <- chronogram_skeleton(
  ids = c(1, 2, 3, 3),
  start_date = "01012020",
  end_date = "10102021"
)
#> Warning: Duplicate IDs found :  3 Check your input ID vector...
#>       provide a unique identifier for
#>       each individual
#> Returning a de-duplicated chronogram_skeleton...