diff --git a/DESCRIPTION b/DESCRIPTION index 501e2cf..7b146d3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,6 +20,7 @@ Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.3 Imports: + cli, DBI, dbplyr, dplyr, @@ -29,7 +30,8 @@ Imports: lobstr, lubridate, magrittr, - patchwork, + patchwork, + pillar, purrr, rlang (>= 0.4.11), RSQLite, diff --git a/NAMESPACE b/NAMESPACE index de7b903..dcda475 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -15,9 +15,10 @@ S3method(glimpse,grouped_cg_df) S3method(glimpse_experiment_data,cg_tbl) S3method(glimpse_metadata,cg_tbl) S3method(group_by,cg_tbl) -S3method(print,cg_skl_tbl) -S3method(print,cg_tbl) -S3method(print,grouped_cg_df) +S3method(summary,cg_tbl) +S3method(summary,grouped_cg_df) +S3method(tbl_format_footer,cg_tbl) +S3method(tbl_sum,cg_tbl) S3method(ungroup,grouped_cg_df) export("%>%") export(":=") @@ -59,6 +60,8 @@ importFrom(dplyr,group_by) importFrom(dplyr,group_data) importFrom(dplyr,ungroup) importFrom(magrittr,"%>%") +importFrom(pillar,tbl_format_footer) +importFrom(pillar,tbl_sum) importFrom(rlang,":=") importFrom(rlang,.data) importFrom(rlang,as_label) diff --git a/R/check_metadata.R b/R/check_metadata.R index b9c5169..dd8b910 100644 --- a/R/check_metadata.R +++ b/R/check_metadata.R @@ -29,5 +29,27 @@ check_metadata <- function(x, cg_skeleton = NULL) { ) } + ### metadata should not have duplicated ids ### + if (!is.null(ids_column_name)) { + stopifnot( + { + n <- NULL # suppress global binding note + "Invalid metadata: IDs are repeated" = + xx <- x %>% + dplyr::group_by( + dplyr::across( + dplyr::all_of( + c(ids_column_name) + ) + ) + ) %>% + dplyr::tally() %>% + dplyr::pull(n) + + all(xx < 2) == TRUE + } + ) + } + return(TRUE) } diff --git a/R/new_chronogram.R b/R/new_chronogram.R index 93c0ea6..bde0ccd 100644 --- a/R/new_chronogram.R +++ b/R/new_chronogram.R @@ -1,6 +1,6 @@ #' new chronogram #' -#' @param x a tbl, a daughter of a join between a cg_skl_tbl and +#' @param x a tbl, a daughter of a join between a chronogram skeleton and #' one (or more) objects coerced to a tbl. #' @param metadata_cols the column names from the metadata tibble #' @param ... passed to `new_tibble()`. Adds grouping support. @@ -17,8 +17,8 @@ new_chronogram <- function(x, metadata_cols, ...) { stopifnot( - "provided object does not inherit cg_skl_tbl class" = - inherits(x, "cg_skl_tbl") + "provided object does not inherit tbl_df class" = + inherits(x, "tbl_df") ) stopifnot( @@ -29,11 +29,6 @@ new_chronogram <- function(x, ## Set first class to cg_tbl ## class(x) <- c("cg_tbl", class(x)) - ## remove the cg_skl_tbl class ## - class(x) <- class(x)[ - !grepl(class(x), pattern = "cg_skl_tbl") - ] - ## remove the col_ids from metadata column names ## col_ids <- attributes(x)$col_ids cols_metadata <- metadata_cols[ diff --git a/R/new_chronogram_skeleton.R b/R/new_chronogram_skeleton.R index 9a86333..22adc80 100644 --- a/R/new_chronogram_skeleton.R +++ b/R/new_chronogram_skeleton.R @@ -9,7 +9,7 @@ #' rlang::enquo(an_unquoted_string) #' @param ids_col provided as rlang::enquo(an_unquoted_string) #' -#' @return x a tibble with class cg_skl_tbl +#' @return x a tibble with attributes to identify `calendar_date_col` and `ids_col`. #' #' @seealso [chronogram::chronogram_skeleton()] #' @@ -55,7 +55,5 @@ new_chronogram_skeleton <- function(x, attributes(x) <- attributes_x - class(x) <- c("cg_skl_tbl", class(x)) - return(x) } diff --git a/R/print_chronogram.R b/R/print_chronogram.R index 28c6345..41c2648 100644 --- a/R/print_chronogram.R +++ b/R/print_chronogram.R @@ -1,130 +1,66 @@ -#' print chronogram +#' Add a line to tbl header when printing a chronogram, or a grouped chronogram #' -#' @param x a chronogram object (class tbl_chronogram) -#' @param ... additional arguments passed to tibble print S3 generic +#' @param x a chronogram, or a grouped chronogram +#' (class tbl_chronogram or grouped_cg_df) +#' @param ... passed to [pillar::tbl_sum()] #' #' @return print to console -#' @examples -#' \dontrun{ -#' ## a 3-person chronogram_skeleton ## -#' small_study <- chronogram_skeleton( -#' col_ids = elig_study_id, -#' ids = c(1, 2, 3), -#' start_date = "01012020", -#' end_date = "10102021", -#' col_calendar_date = calendar_date -#' ) #' -#' ## Create a tibble containing some metadata for our 3 individuals ## -#' small_study_metadata <- tibble::tribble( -#' ~elig_study_id, ~age, ~sex, ~dose_1, ~date_dose_1, ~dose_2, ~date_dose_2, -#' 1, 40, "F", "AZD1222", "05/01/2021", "AZD1222", "05/02/2021", -#' 2, 45, "F", "BNT162b2", "05/01/2021", "BNT162b2", "05/02/2021", -#' 3, 35, "M", "BNT162b2", "10/01/2021", "BNT162b2", "10/03/2021" -#' ) -#' -#' ## Set appropriate metadata column classes ## -#' library(dplyr) -#' small_study_metadata <- small_study_metadata %>% -#' mutate(across(c(sex, dose_1, dose_2), ~ as.factor(.x))) -#' -#' small_study_metadata <- small_study_metadata %>% -#' mutate(across(contains("date"), ~ lubridate::dmy(.x))) -#' -#' ## Make a chronogram ## -#' small_study_chronogram <- chronogram( -#' small_study, -#' small_study_metadata -#' ) -#' -#' ## print, with default tibble options ## -#' small_study_chronogram -#' -#' ## print, with eg 3 rows ## -#' print(small_study_chronogram, n = 3) -#' } +#' @importFrom pillar tbl_sum +#' @seealso [summary()] #' @export -print.cg_tbl <- function(x, ...) { - calendar_date <- attributes(x)$col_calendar_date - ids_column_name <- attributes(x)$col_ids - version_number <- attributes(x)$cg_pkg_version - windowed <- attributes(x)$windowed - meta <- attributes(x)$cols_metadata - - zz <- NULL # suppress no visible binding warning - - over_min <- x %>% - dplyr::group_by( - dplyr::across( - dplyr::all_of(ids_column_name) - ) - ) %>% - dplyr::summarise(zz = (dplyr::n())) %>% - dplyr::pull(zz) %>% - min(., na.rm = TRUE) +#' @noRd - over_max <- x %>% - dplyr::group_by( - dplyr::across( - dplyr::all_of(ids_column_name) - ) - ) %>% - dplyr::summarise(zz = (dplyr::n())) %>% - dplyr::pull(zz) %>% - max(., na.rm = TRUE) - - cat( - ## use paste to prevent cat re-formating dates - paste( - "A chronogram:\n", - "Dates column: ", calendar_date, "\n", - "IDs column: ", ids_column_name, "\n", - "Starts on: ", - min(x %>% dplyr::pull(calendar_date)), "\n", - "Ends on: ", - max(x %>% dplyr::pull(calendar_date)), "\n", - # "Spanning: ", - # max(x %>% dplyr::pull( calendar_date )) - - # min(x %>% dplyr::pull( calendar_date )), - # " days\n", - "Contains: ", - x %>% dplyr::pull(ids_column_name) %>% - factor(.) %>% nlevels(.), - " unique participant IDs\n", - "Windowed: ", windowed, "\n", - "Spanning: ", - over_min, - "-", - over_max, "days [min-max per participant]\n", - "Metadata: ", - paste(meta, collapse = ", "), "\n", - "Size: ", - rlang::parse_bytes( - as.character( - lobstr::obj_size(x) - ) - ), "\n", - "Pkg_version: ", - version_number, "[used to build this cg]\n\n" - ) - ) - NextMethod(x, ...) +tbl_sum.cg_tbl <- function(x, ...) { + default_header <- NextMethod() + c(default_header, "A chronogram" = cli::col_blue("try summary()")) } +#' Add a line to tbl footer when printing a chronogram, or a grouped chronogram +#' @importFrom pillar tbl_format_footer +#' @param ... passed to [pillar::tbl_format_footer()] +#' @export +#' @noRd +tbl_format_footer.cg_tbl <- function(x, setup, ...) { + default_footer <- NextMethod() + meta <- paste(attributes(x)$cols_metadata, collapse = ", ") + extra_info <- paste( + cli::col_yellow("Dates:"), + attributes(x)$col_calendar_date, + " ", + cli::col_yellow(cli::symbol$star), + cli::col_yellow("IDs:"), + attributes(x)$col_ids) -#' @export -print.grouped_cg_df <- function(x, ...) { - groups <- dplyr::group_vars(x) + extra_info_meta <- paste(cli::col_yellow("metadata:"), meta) - cat( - paste( - "A grouped chronogram", "\n", - "Groups: ", paste(groups, collapse = ", "), "\n", - "... now printing chronogram view ...", "\n" + extra_footer <- paste0( + pillar::style_subtle(paste0("# ", cli::col_yellow(cli::symbol$star), " ", (extra_info))), + "\n", + pillar::style_subtle(paste0("# ", cli::col_yellow(cli::symbol$star), " ", (extra_info_meta))) ) - ) - - NextMethod(x, ...) + c(default_footer, extra_footer) } + + +#' This is draft code to fine tune display of the pillars themselves. +#' +#' #' @importFrom pillar ctl_new_pillar +#' #' @importFrom pillar new_pillar_component +#' #' @importFrom pillar new_pillar +#' #' @export +#' ctl_new_pillar.cg_tbl <- function(controller, x, width, ..., title = NULL) { +#' out <- NextMethod() +#' +#' pillar::new_pillar(list( +#' top_rule = pillar::new_pillar_component(list("========"), width = 8), +#' title = out$title, +#' type = out$type, +#' mid_rule = pillar::new_pillar_component(list("--------"), width = 8), +#' data = out$data, +#' bottom_rule = pillar::new_pillar_component(list("========"), width = 8) +#' )) +#' } + diff --git a/R/print_chronogram_skeleton.R b/R/print_chronogram_skeleton.R deleted file mode 100644 index bc866cb..0000000 --- a/R/print_chronogram_skeleton.R +++ /dev/null @@ -1,61 +0,0 @@ -#' print chronogram skeleton -#' -#' @param x a chronogram skeleton object (class cg_skl_tbl) -#' @param ... additional arguments passed to tibble::print S3 generic -#' -#' @return print to console -#' -#' @export -#' @examples -#' \dontrun{ -#' small.study <- chronogram_skeleton( -#' ids = c(1, 2, 3), -#' start_date = "01012020", -#' end_date = "10102021" -#' ) -#' -#' ## print, with default tibble options ## -#' small.study -#' -#' ## print, with eg 3 rows ## -#' print(small.study, n = 3) -#' } -print.cg_skl_tbl <- function( - x, ...) { - calendar_date <- attributes(x)$col_calendar_date - ids_column_name <- attributes(x)$col_ids - version_number <- attributes(x)$cg_pkg_version - - cat( - ## use paste to prevent cat re-formatting dates - paste( - "A chronogram skeleton:\n", - "Dates column: ", calendar_date, "\n", - "IDs column: ", ids_column_name, "\n", - "Starts on: ", - min(x %>% dplyr::pull(calendar_date)), "\n", - "Ends on: ", - max(x %>% dplyr::pull(calendar_date)), "\n", - "Spanning: ", - max(x %>% - dplyr::pull(calendar_date)) - - min(x %>% dplyr::pull(calendar_date)) + 1, - " days\n", - "Contains: ", - x %>% - dplyr::pull(ids_column_name) %>% - factor(.) %>% nlevels(.), - " unique participant IDs\n", - "Size: ", - rlang::parse_bytes( - as.character( - lobstr::obj_size(x) - ) - ), "\n", - "Pkg_version: ", - version_number, "[used to build this cg]\n\n" - ) - ) - - NextMethod(x, ...) -} diff --git a/R/summary_chronogram.R b/R/summary_chronogram.R new file mode 100644 index 0000000..8318f56 --- /dev/null +++ b/R/summary_chronogram.R @@ -0,0 +1,135 @@ +#' summary chronogram +#' +#' @param x a chronogram object (class tbl_chronogram) +#' +#' @return print to console +#' @examples +#' \dontrun{ +#' ## a 3-person chronogram_skeleton ## +#' small_study <- chronogram_skeleton( +#' col_ids = elig_study_id, +#' ids = c(1, 2, 3), +#' start_date = "01012020", +#' end_date = "10102021", +#' col_calendar_date = calendar_date +#' ) +#' +#' ## Create a tibble containing some metadata for our 3 individuals ## +#' small_study_metadata <- tibble::tribble( +#' ~elig_study_id, ~age, ~sex, ~dose_1, ~date_dose_1, ~dose_2, ~date_dose_2, +#' 1, 40, "F", "AZD1222", "05/01/2021", "AZD1222", "05/02/2021", +#' 2, 45, "F", "BNT162b2", "05/01/2021", "BNT162b2", "05/02/2021", +#' 3, 35, "M", "BNT162b2", "10/01/2021", "BNT162b2", "10/03/2021" +#' ) +#' +#' ## Set appropriate metadata column classes ## +#' library(dplyr) +#' small_study_metadata <- small_study_metadata %>% +#' mutate(across(c(sex, dose_1, dose_2), ~ as.factor(.x))) +#' +#' small_study_metadata <- small_study_metadata %>% +#' mutate(across(contains("date"), ~ lubridate::dmy(.x))) +#' +#' ## Make a chronogram ## +#' small_study_chronogram <- chronogram( +#' small_study, +#' small_study_metadata +#' ) +#' +#' ## print, with default tibble options ## +#' small_study_chronogram +#' +#' ## print, with eg 3 rows ## +#' print(small_study_chronogram, n = 3) +#' } +#' @export +#' @noRd +#' +summary.cg_tbl <- function(object, ...) { + x <- object + + calendar_date <- attributes(x)$col_calendar_date + ids_column_name <- attributes(x)$col_ids + version_number <- attributes(x)$cg_pkg_version + windowed <- attributes(x)$windowed + meta <- attributes(x)$cols_metadata + + zz <- NULL # suppress no visible binding warning + + over_min <- x %>% + dplyr::group_by( + dplyr::across( + dplyr::all_of(ids_column_name) + ) + ) %>% + dplyr::summarise(zz = (dplyr::n())) %>% + dplyr::pull(zz) %>% + min(., na.rm = TRUE) + + over_max <- x %>% + dplyr::group_by( + dplyr::across( + dplyr::all_of(ids_column_name) + ) + ) %>% + dplyr::summarise(zz = (dplyr::n())) %>% + dplyr::pull(zz) %>% + max(., na.rm = TRUE) + + cat( + ## use paste to prevent cat re-formating dates + paste( + "A chronogram:\n", + "Dates column: ", calendar_date, "\n", + "IDs column: ", ids_column_name, "\n", + "Starts on: ", + min(x %>% dplyr::pull(calendar_date)), "\n", + "Ends on: ", + max(x %>% dplyr::pull(calendar_date)), "\n", + # "Spanning: ", + # max(x %>% dplyr::pull( calendar_date )) - + # min(x %>% dplyr::pull( calendar_date )), + # " days\n", + "Contains: ", + x %>% dplyr::pull(ids_column_name) %>% + factor(.) %>% nlevels(.), + " unique participant IDs\n", + "Windowed: ", windowed, "\n", + "Spanning: ", + over_min, + "-", + over_max, "days [min-max per participant]\n", + "Metadata: ", + paste(meta, collapse = ", "), "\n", + "Size: ", + rlang::parse_bytes( + as.character( + lobstr::obj_size(x) + ) + ), "\n", + "Pkg_version: ", + version_number, "[used to build this cg]\n\n" + ) + ) +} + + + + +#' @export +#' @noRd +summary.grouped_cg_df <- function(object, ...) { + + x <- object + groups <- dplyr::group_vars(x) + + cat( + paste( + "A grouped chronogram", "\n", + "Groups: ", paste(groups, collapse = ", "), "\n", + "... now summarising whole chronogram ...", "\n" + ) + ) + + NextMethod(x, ...) +} diff --git a/R/validate_chronogram_skeleton.R b/R/validate_chronogram_skeleton.R index c75db9e..3a3892f 100644 --- a/R/validate_chronogram_skeleton.R +++ b/R/validate_chronogram_skeleton.R @@ -1,13 +1,13 @@ #' validate chronogram skeleton #' -#' @param x a chronogram skeleton object (class cg_skl_tbl) +#' @param x a chronogram skeleton object (class tbl_df, with attributes that record IDs and date columns) #' -#' @return Errors, or TRUE if valid cg_skl_tbl +#' @return Errors, or TRUE if valid chronogram skeleton #' validate_chronogram_skeleton <- function(x) { stopifnot( "Invalid cg_skeleton: Wrong class. Use 'chronogram_skeleton()'" = - inherits(x, "cg_skl_tbl") == TRUE + inherits(x, "tbl_df") == TRUE ) stopifnot( diff --git a/chronogram.Rproj b/chronogram.Rproj new file mode 100644 index 0000000..21a4da0 --- /dev/null +++ b/chronogram.Rproj @@ -0,0 +1,17 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source diff --git a/data/built_smallstudy.rda b/data/built_smallstudy.rda index d71d678..26ad727 100644 Binary files a/data/built_smallstudy.rda and b/data/built_smallstudy.rda differ diff --git a/data/pitch_chronogram.rda b/data/pitch_chronogram.rda index 773efe9..89d1e8a 100644 Binary files a/data/pitch_chronogram.rda and b/data/pitch_chronogram.rda differ diff --git a/inst/extdata/pitch-database-output.sqlite b/inst/extdata/pitch-database-output.sqlite index 1208e4a..707e112 100644 Binary files a/inst/extdata/pitch-database-output.sqlite and b/inst/extdata/pitch-database-output.sqlite differ diff --git a/man/new_chronogram.Rd b/man/new_chronogram.Rd index 190daa6..7c8b64f 100644 --- a/man/new_chronogram.Rd +++ b/man/new_chronogram.Rd @@ -7,7 +7,7 @@ new_chronogram(x, metadata_cols, ...) } \arguments{ -\item{x}{a tbl, a daughter of a join between a cg_skl_tbl and +\item{x}{a tbl, a daughter of a join between a chronogram skeleton and one (or more) objects coerced to a tbl.} \item{metadata_cols}{the column names from the metadata tibble} diff --git a/man/new_chronogram_skeleton.Rd b/man/new_chronogram_skeleton.Rd index cd60e50..dcb10d0 100644 --- a/man/new_chronogram_skeleton.Rd +++ b/man/new_chronogram_skeleton.Rd @@ -15,7 +15,7 @@ rlang::enquo(an_unquoted_string)} \item{ids_col}{provided as rlang::enquo(an_unquoted_string)} } \value{ -x a tibble with class cg_skl_tbl +x a tibble with attributes to identify \code{calendar_date_col} and \code{ids_col}. } \description{ A low level constructor function. Use the helper diff --git a/man/print.cg_skl_tbl.Rd b/man/print.cg_skl_tbl.Rd deleted file mode 100644 index 72be5db..0000000 --- a/man/print.cg_skl_tbl.Rd +++ /dev/null @@ -1,34 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/print_chronogram_skeleton.R -\name{print.cg_skl_tbl} -\alias{print.cg_skl_tbl} -\title{print chronogram skeleton} -\usage{ -\method{print}{cg_skl_tbl}(x, ...) -} -\arguments{ -\item{x}{a chronogram skeleton object (class cg_skl_tbl)} - -\item{...}{additional arguments passed to tibble::print S3 generic} -} -\value{ -print to console -} -\description{ -print chronogram skeleton -} -\examples{ -\dontrun{ -small.study <- chronogram_skeleton( - ids = c(1, 2, 3), - start_date = "01012020", - end_date = "10102021" -) - -## print, with default tibble options ## -small.study - -## print, with eg 3 rows ## -print(small.study, n = 3) -} -} diff --git a/man/print.cg_tbl.Rd b/man/print.cg_tbl.Rd deleted file mode 100644 index a576b9d..0000000 --- a/man/print.cg_tbl.Rd +++ /dev/null @@ -1,59 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/print_chronogram.R -\name{print.cg_tbl} -\alias{print.cg_tbl} -\title{print chronogram} -\usage{ -\method{print}{cg_tbl}(x, ...) -} -\arguments{ -\item{x}{a chronogram object (class tbl_chronogram)} - -\item{...}{additional arguments passed to tibble print S3 generic} -} -\value{ -print to console -} -\description{ -print chronogram -} -\examples{ -\dontrun{ -## a 3-person chronogram_skeleton ## -small_study <- chronogram_skeleton( - col_ids = elig_study_id, - ids = c(1, 2, 3), - start_date = "01012020", - end_date = "10102021", - col_calendar_date = calendar_date -) - -## Create a tibble containing some metadata for our 3 individuals ## -small_study_metadata <- tibble::tribble( - ~elig_study_id, ~age, ~sex, ~dose_1, ~date_dose_1, ~dose_2, ~date_dose_2, - 1, 40, "F", "AZD1222", "05/01/2021", "AZD1222", "05/02/2021", - 2, 45, "F", "BNT162b2", "05/01/2021", "BNT162b2", "05/02/2021", - 3, 35, "M", "BNT162b2", "10/01/2021", "BNT162b2", "10/03/2021" -) - -## Set appropriate metadata column classes ## -library(dplyr) -small_study_metadata <- small_study_metadata \%>\% - mutate(across(c(sex, dose_1, dose_2), ~ as.factor(.x))) - -small_study_metadata <- small_study_metadata \%>\% - mutate(across(contains("date"), ~ lubridate::dmy(.x))) - -## Make a chronogram ## -small_study_chronogram <- chronogram( - small_study, - small_study_metadata -) - -## print, with default tibble options ## -small_study_chronogram - -## print, with eg 3 rows ## -print(small_study_chronogram, n = 3) -} -} diff --git a/man/validate_chronogram_skeleton.Rd b/man/validate_chronogram_skeleton.Rd index 843df83..dc22746 100644 --- a/man/validate_chronogram_skeleton.Rd +++ b/man/validate_chronogram_skeleton.Rd @@ -7,10 +7,10 @@ validate_chronogram_skeleton(x) } \arguments{ -\item{x}{a chronogram skeleton object (class cg_skl_tbl)} +\item{x}{a chronogram skeleton object (class tbl_df, with attributes that record IDs and date columns)} } \value{ -Errors, or TRUE if valid cg_skl_tbl +Errors, or TRUE if valid chronogram skeleton } \description{ validate chronogram skeleton diff --git a/tests/testthat/test-chronogram_skeleton.R b/tests/testthat/test-chronogram_skeleton.R index 1a3a216..91f27f2 100644 --- a/tests/testthat/test-chronogram_skeleton.R +++ b/tests/testthat/test-chronogram_skeleton.R @@ -11,7 +11,7 @@ small_study <- chronogram::chronogram_skeleton( test_that("chronogram_skeleton: correct class", { expect_s3_class( small_study, - "cg_skl_tbl" + "tbl_df" ) }) @@ -79,3 +79,45 @@ test_that( ) } ) + +test_that( + "chronogram_skeleton: includes an ID column in attributes", + { + expect_false( + is.na(attributes(small_study)$col_ids) | + is.null(attributes(small_study)$col_ids) + ) + } +) + +test_that( + "chronogram_skeleton: includes an date column in attributes", + { + expect_false( + is.na(attributes(small_study)$col_calendar_date) | + is.null(attributes(small_study)$col_calendar_date) + ) + } +) + + +test_that( + "chronogram_skeleton: date column in attributes is a column name", + { + expect_true( + attributes(small_study)$col_calendar_date %in% colnames(small_study) + ) + } +) + +test_that( + "chronogram_skeleton: ID column in attributes is a column name", + { + expect_true( + attributes(small_study)$col_ids %in% colnames(small_study) + ) + } +) + + + diff --git a/tests/testthat/test-new_chronogram.R b/tests/testthat/test-new_chronogram.R index 9e3c9bd..63ef3f5 100644 --- a/tests/testthat/test-new_chronogram.R +++ b/tests/testthat/test-new_chronogram.R @@ -17,15 +17,12 @@ by_hand_cg <- dplyr::left_join( -test_that("input is not of class cg_skl_tbl", { - expect_error( - ## provide an input object of wrong class ## - new_chronogram( +test_that("input chronogram skeleton is class tbl_df", { + expect_s3_class( metadata, - metadata - ), - "provided object does not inherit cg_skl_tbl class" - ) + c("tbl_df", "tbl", "data.frame"), + exact = T + ) }) test_that("input metadata_cols not a character vector", {