Running 'testthat.R' [48s]
Running the tests in 'tests/testthat.R' failed.
Complete output:
  > # This file is part of the standard setup for testthat.
  > # It is recommended that you do not modify it.
  > #
  > # Where should you do additional test configuration?
  > # Learn more about the roles of various files in:
  > # * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
  > # * https://testthat.r-lib.org/articles/special-files.html
  > 
  > library(testthat)
  > library(healthdb)
  > 
  > test_check("healthdb")
  Saving _problems/test-collapse_episode-7.R
  
  The following records have start > end:
     uid clnt_id      dates   ans diagx diagx_1 diagx_2   end_date
  1    3       1 2020-12-19   any     d       q     999 2020-12-12
  2    1       1 2020-12-28   any     t       v    <NA> 2020-12-21
  3    5       5 2019-08-29   any     d       b     999 2019-08-22
  4    2      10 2018-10-27   any     x       d    <NA> 2018-10-20
  5   13      12 2016-09-06 noise   999    <NA>     999 2016-08-30
  6   24      13 2017-07-07 noise   999     999    <NA> 2017-06-30
  7   20      16 2017-09-22 noise   999    <NA>    <NA> 2017-09-15
  8    7      17 2018-03-24   any     p       h    <NA> 2018-03-17
  9   16      18 2015-06-04 noise   999    <NA>     999 2015-05-28
  10  12      19 2015-09-08   all     z       w       f 2015-09-01
  11  11      21 2018-01-24   all     c       u       d 2018-01-17
  12  14      21 2018-08-17 noise   999    <NA>    <NA> 2018-08-10
  13   6      21 2020-08-16   any     b    <NA>     999 2020-08-09
  14  21      22 2016-08-31 noise   999    <NA>    <NA> 2016-08-24
  15   9      25 2020-11-30   all     b       h       i 2020-11-23
  16  18      30 2018-02-22 noise   999     999     999 2018-02-15
  17   8      34 2017-02-12   any     x       b     999 2017-02-05
  18  10      34 2018-10-12   all     b       g       r 2018-10-05
  19  19      36 2019-04-30 noise   999     999    <NA> 2019-04-23
  20  23      38 2016-05-19 noise   999     999     999 2016-05-12
  21  15      45 2016-06-27 noise   999    <NA>     999 2016-06-20
  22  25      47 2015-04-19 noise   999     999     999 2015-04-12
  23   4      47 2017-08-30   any     f       v    <NA> 2017-08-23
  24  17      48 2017-02-04 noise   999    <NA>     999 2017-01-28
  25  22      50 2015-02-22 noise   999    <NA>     999 2015-02-15
  
  The following records have missing dates:
    uid clnt_id      dates ans diagx diagx_1 diagx_2 end_date
  1   1      39 2017-09-09 any     u       d     999       NA
  > --------------Inclusion step--------------
  
  i Identify records with condition(s):
  * where at least one of the diagx, diagx_1, diagx_2 column(s) in each record
  * contains a value exactly matched values in set: letters
  i To see the final query generated by 'dbplyr', use dplyr::show_query() on the output.
  To extract the SQL string, use dbplyr::remote_query().
  
  This message is displayed once per session.
  > --------------Exclusion step--------------
  
  i Identify records with condition(s):
  * where at least one of the diagx, diagx_1, diagx_2 column(s) in each record
  * contains a value exactly matched values in set: c("a", "b")
  i Exclude records in `data` through anti_join with `excl` matching on (by argument): "clnt_id" 
  
  > --------------No. rows restriction--------------
  
  i Apply restriction that each client must have at least 2 records with distinct dates. Clients/groups which did not met the condition were excluded.
  > --------------Time span restriction--------------
  
  Saving _problems/test-define_case-85.R
  Saving _problems/test-define_case-94.R
  i Exclude a subset of `data` that satisfies condition: ans == "noise" 
  Check NAs in the result; SQL handles missing value differently compared to R.
  
  i Exclude a subset of `data` that satisfies condition: ans == "noise" 
  
  i Consider being explicit about NA, e.g., condition = var == 'val' | is.na(var)
  
  i Exclude a subset of `data` that satisfies condition: ans == "noise" 
  Check NAs in the result; SQL handles missing value differently compared to R.
  
  i Consider being explicit about NA, e.g., condition = var == 'val' | is.na(var)
  
  Saving _problems/test-execute_def-12.R
  Saving _problems/test-execute_def-35.R
  Saving _problems/test-execute_def-66.R
  Saving _problems/test-execute_def-102.R
  Saving _problems/test-identify_rows_dataframe-3.R
  Saving _problems/test-identify_rows_dataframe-11.R
  Saving _problems/test-identify_rows_dataframe-18.R
  Saving _problems/test-identify_rows_dataframe-26.R
  Saving _problems/test-identify_rows_dataframe-34.R
  Saving _problems/test-identify_rows_dataframe-43.R
  Saving _problems/test-identify_rows_dataframe-49.R
  Saving _problems/test-identify_rows_dataframe-62.R
  Saving _problems/test-identify_rows_dataframe-68.R
  Saving _problems/test-identify_rows_dataframe-75.R
  Saving _problems/test-if_dates-41.R
  Saving _problems/test-pool_case-45.R
  Saving _problems/test-pool_case-64.R
  Saving _problems/test-pool_case-83.R
  Saving _problems/test-pool_case-134.R
  [ FAIL 23 | WARN 2 | SKIP 6 | PASS 189 ]
  
  ══ Skipped tests (6) ═══════════════════════════════════════════════════════════
  • On CRAN (6): 'test-define_case.R:42:3', 'test-if_dates.R:2:3',
    'test-if_dates.R:26:3', 'test-if_dates.R:33:3',
    'test-restrict_dates_sql.R:26:3', 'test-restrict_dates_sql.R:101:3'
  
  ══ Failed tests ════════════════════════════════════════════════════════════════
  ── Error ('test-collapse_episode.R:7:3'): basic use works ──────────────────────
  Error in ``[.data.table`(data, , `:=`(last_end_dt, lapply(.SD, function(x) data.table::shift(x, n = 1, fill = data.table::first(x)))), by = clnt_id_nm, .SDcols = end_dt_nm)`: attempt access index 8/8 in VECTOR_ELT
  Backtrace:
      ▆
   1. ├─healthdb::collapse_episode(...) at test-collapse_episode.R:7:3
   2. └─healthdb:::collapse_episode.data.frame(...)
   3.   ├─...[]
   4.   └─data.table:::`[.data.table`(...)
  ── Error ('test-define_case.R:85:48'): keep first/last works on df ─────────────
  Error in ``[.data.table`(dt, , `:=`(incl, data.table::`%chin%`(unlist(.SD), matched_vals) %>% combine_fn(na.rm = TRUE)), by = "rid", .SDcols = vars)`: attempt access index 8/8 in VECTOR_ELT
  Backtrace:
       ▆
    1. └─base::sapply(...) at test-define_case.R:85:3
    2.   └─base::lapply(X = X, FUN = FUN, ...)
    3.     └─healthdb (local) FUN(X[[i]], ...)
    4.       └─healthdb::define_case(...) at test-define_case.R:85:48
    5.         ├─base::eval(incl)
    6.         │ └─base::eval(incl)
    7.         ├─healthdb::identify_row(...)
    8.         └─healthdb:::identify_rows.data.frame(...)
    9.           ├─...[]
   10.           └─data.table:::`[.data.table`(...)
  ── Error ('test-define_case.R:94:3'): passing ... works ────────────────────────
  Error in ``[.data.table`(dt, , `:=`(incl, data.table::`%chin%`(unlist(.SD), matched_vals) %>% combine_fn(na.rm = TRUE)), by = "rid", .SDcols = vars)`: attempt access index 7/7 in VECTOR_ELT
  Backtrace:
      ▆
   1. └─healthdb::define_case(...) at test-define_case.R:94:3
   2.   ├─base::eval(incl)
   3.   │ └─base::eval(incl)
   4.   ├─healthdb::identify_row(...)
   5.   └─healthdb:::identify_rows.data.frame(...)
   6.     ├─...[]
   7.     └─data.table:::`[.data.table`(...)
  ── Error ('test-execute_def.R:12:3'): basic use works ──────────────────────────
  <dplyr:::mutate_error/rlang_error/error/condition>
  Error in `dplyr::mutate(., result = purrr::pmap(list(.data[["fn_call"]], .data[["src_labs"]], .data[["def_lab"]]), function(x, y, z) {     if (getOption("healthdb.verbose"))          rlang::inform(paste0("\nActions for definition ", z, " using source ", rlang::expr_deparse(with_data_expr[[y]]), ":\n"))     eval(x, envir = with_data_env) }, .progress = TRUE), result = purrr::pmap(list(.data[["result"]], .data[["def_lab"]], .data[["src_labs"]]), function(dat, def, src) {     dat %>% dplyr::mutate(def = def, src = src, .before = 1) }))`: i In argument: `result = purrr::pmap(...)`.
  Caused by error in `purrr::pmap()`:
  i In index: 2.
  Caused by error in `[.data.table`:
  ! attempt access index 8/8 in VECTOR_ELT
  ── Error ('test-execute_def.R:35:3'): mixed binding works ──────────────────────
  <dplyr:::mutate_error/rlang_error/error/condition>
  Error in `dplyr::mutate(., result = purrr::pmap(list(.data[["fn_call"]], .data[["src_labs"]], .data[["def_lab"]]), function(x, y, z) {     if (getOption("healthdb.verbose"))          rlang::inform(paste0("\nActions for definition ", z, " using source ", rlang::expr_deparse(with_data_expr[[y]]), ":\n"))     eval(x, envir = with_data_env) }, .progress = TRUE), result = purrr::pmap(list(.data[["result"]], .data[["def_lab"]], .data[["src_labs"]]), function(dat, def, src) {     dat %>% dplyr::mutate(def = def, src = src, .before = 1) }))`: i In argument: `result = purrr::pmap(...)`.
  Caused by error in `purrr::pmap()`:
  i In index: 2.
  Caused by error in `[.data.table`:
  ! attempt access index 8/8 in VECTOR_ELT
  ── Error ('test-execute_def.R:66:3'): binding dfs works ────────────────────────
  <dplyr:::mutate_error/rlang_error/error/condition>
  Error in `dplyr::mutate(., result = purrr::pmap(list(.data[["fn_call"]], .data[["src_labs"]], .data[["def_lab"]]), function(x, y, z) {     if (getOption("healthdb.verbose"))          rlang::inform(paste0("\nActions for definition ", z, " using source ", rlang::expr_deparse(with_data_expr[[y]]), ":\n"))     eval(x, envir = with_data_env) }, .progress = TRUE), result = purrr::pmap(list(.data[["result"]], .data[["def_lab"]], .data[["src_labs"]]), function(dat, def, src) {     dat %>% dplyr::mutate(def = def, src = src, .before = 1) }))`: i In argument: `result = purrr::pmap(...)`.
  Caused by error in `purrr::pmap()`:
  i In index: 1.
  Caused by error in `[.data.table`:
  ! attempt access index 8/8 in VECTOR_ELT
  ── Error ('test-execute_def.R:102:3'): multiple def works ──────────────────────
  <dplyr:::mutate_error/rlang_error/error/condition>
  Error in `dplyr::mutate(., result = purrr::pmap(list(.data[["fn_call"]], .data[["src_labs"]], .data[["def_lab"]]), function(x, y, z) {     if (getOption("healthdb.verbose"))          rlang::inform(paste0("\nActions for definition ", z, " using source ", rlang::expr_deparse(with_data_expr[[y]]), ":\n"))     eval(x, envir = with_data_env) }, .progress = TRUE), result = purrr::pmap(list(.data[["result"]], .data[["def_lab"]], .data[["src_labs"]]), function(dat, def, src) {     dat %>% dplyr::mutate(def = def, src = src, .before = 1) }))`: i In argument: `result = purrr::pmap(...)`.
  Caused by error in `purrr::pmap()`:
  i In index: 1.
  Caused by error in `[.data.table`:
  ! attempt access index 8/8 in VECTOR_ELT
  ── Error ('test-identify_rows_dataframe.R:3:3'): match by in works ─────────────
  Error in ``[.data.table`(dt, , `:=`(incl, data.table::`%chin%`(unlist(.SD), matched_vals) %>% combine_fn(na.rm = TRUE)), by = "rid", .SDcols = vars)`: attempt access index 8/8 in VECTOR_ELT
  Backtrace:
      ▆
   1. ├─healthdb:::identify_rows(df, starts_with("diagx"), "in", letters) at test-identify_rows_dataframe.R:3:3
   2. └─healthdb:::identify_rows.data.frame(...)
   3.   ├─...[]
   4.   └─data.table:::`[.data.table`(...)
  ── Error ('test-identify_rows_dataframe.R:11:3'): if_all works ─────────────────
  Error in ``[.data.table`(dt, , `:=`(incl, data.table::`%chin%`(unlist(.SD), matched_vals) %>% combine_fn(na.rm = TRUE)), by = "rid", .SDcols = vars)`: attempt access index 8/8 in VECTOR_ELT
  Backtrace:
      ▆
   1. ├─healthdb:::identify_rows(...) at test-identify_rows_dataframe.R:11:3
   2. └─healthdb:::identify_rows.data.frame(...)
   3.   ├─...[]
   4.   └─data.table:::`[.data.table`(...)
  ── Error ('test-identify_rows_dataframe.R:18:3'): match by start works ─────────
  Error in ``[.data.table`(dt, , `:=`(incl, data.table::`%chin%`(unlist(.SD), matched_vals) %>% combine_fn(na.rm = TRUE)), by = "rid", .SDcols = vars)`: attempt access index 8/8 in VECTOR_ELT
  Backtrace:
      ▆
   1. ├─healthdb:::identify_rows(df, starts_with("diagx"), "start", start) at test-identify_rows_dataframe.R:18:3
   2. └─healthdb:::identify_rows.data.frame(...)
   3.   ├─...[]
   4.   └─data.table:::`[.data.table`(...)
  ── Error ('test-identify_rows_dataframe.R:26:3'): match by like works ──────────
  Error in ``[.data.table`(dt, , `:=`(incl, data.table::`%chin%`(unlist(.SD), matched_vals) %>% combine_fn(na.rm = TRUE)), by = "rid", .SDcols = vars)`: attempt access index 8/8 in VECTOR_ELT
  Backtrace:
      ▆
   1. ├─healthdb:::identify_rows(df, starts_with("diagx"), "like", pattern) at test-identify_rows_dataframe.R:26:3
   2. └─healthdb:::identify_rows.data.frame(...)
   3.   ├─...[]
   4.   └─data.table:::`[.data.table`(...)
  ── Error ('test-identify_rows_dataframe.R:34:3'): match by regex works ─────────
  Error in ``[.data.table`(dt, , `:=`(incl, data.table::`%chin%`(unlist(.SD), matched_vals) %>% combine_fn(na.rm = TRUE)), by = "rid", .SDcols = vars)`: attempt access index 8/8 in VECTOR_ELT
  Backtrace:
      ▆
   1. ├─healthdb:::identify_rows(df, starts_with("diagx"), "regex", pattern) at test-identify_rows_dataframe.R:34:3
   2. └─healthdb:::identify_rows.data.frame(...)
   3.   ├─...[]
   4.   └─data.table:::`[.data.table`(...)
  ── Error ('test-identify_rows_dataframe.R:43:3'): match by between works ───────
  Error in ``[.data.table`(dt, , `:=`(incl, unlist(.SD) %in% matched_vals %>% combine_fn(na.rm = TRUE)), by = "rid", .SDcols = vars)`: attempt access index 8/8 in VECTOR_ELT
  Backtrace:
      ▆
   1. ├─healthdb:::identify_rows(df, dates, "between", seq_range) at test-identify_rows_dataframe.R:43:3
   2. └─healthdb:::identify_rows.data.frame(df, dates, "between", seq_range)
   3.   ├─...[]
   4.   └─data.table:::`[.data.table`(...)
  ── Error ('test-identify_rows_dataframe.R:49:3'): type conflict warning works ──
  Error in ``[.data.table`(dt, , `:=`(incl, unlist(.SD) %in% matched_vals %>% combine_fn(na.rm = TRUE)), by = "rid", .SDcols = vars)`: attempt access index 8/8 in VECTOR_ELT
  Backtrace:
       ▆
    1. ├─testthat::expect_warning(...) at test-identify_rows_dataframe.R:49:3
    2. │ └─testthat:::expect_condition_matching_(...)
    3. │   └─testthat:::quasi_capture(...)
    4. │     ├─testthat (local) .capture(...)
    5. │     │ └─base::withCallingHandlers(...)
    6. │     └─rlang::eval_bare(quo_get_expr(.quo), quo_get_env(.quo))
    7. ├─healthdb:::identify_rows(df, starts_with("diagx"), "in", 1:10)
    8. └─healthdb:::identify_rows.data.frame(...)
    9.   ├─...[]
   10.   └─data.table:::`[.data.table`(...)
  ── Error ('test-identify_rows_dataframe.R:56:3'): summary of numeric vals works ──
  Error in ``[.data.table`(dt, , `:=`(incl, unlist(.SD) %in% matched_vals %>% combine_fn(na.rm = TRUE)), by = "rid", .SDcols = vars)`: attempt access index 7/7 in VECTOR_ELT
  Backtrace:
       ▆
    1. ├─testthat::expect_output(...) at test-identify_rows_dataframe.R:56:3
    2. │ └─testthat:::quasi_capture(...)
    3. │   ├─testthat (local) .capture(...)
    4. │   │ └─testthat::capture_output_lines(code, print, width = width)
    5. │   │   └─testthat:::eval_with_output(code, print = print, width = width)
    6. │   │     ├─withr::with_output_sink(path, withVisible(code))
    7. │   │     │ └─base::force(code)
    8. │   │     └─base::withVisible(code)
    9. │   └─rlang::eval_bare(quo_get_expr(.quo), quo_get_env(.quo))
   10. ├─healthdb:::identify_rows(...)
   11. └─healthdb:::identify_rows.data.frame(...)
   12.   ├─...[]
   13.   └─data.table:::`[.data.table`(...)
  ── Error ('test-identify_rows_dataframe.R:62:3'): edge case - character vars works ──
  Error in ``[.data.table`(dt, , `:=`(incl, data.table::`%chin%`(unlist(.SD), matched_vals) %>% combine_fn(na.rm = TRUE)), by = "rid", .SDcols = vars)`: attempt access index 8/8 in VECTOR_ELT
  Backtrace:
      ▆
   1. ├─healthdb:::identify_rows(df, any_of(var_nm), "in", letters) at test-identify_rows_dataframe.R:62:3
   2. └─healthdb:::identify_rows.data.frame(...)
   3.   ├─...[]
   4.   └─data.table:::`[.data.table`(...)
  ── Error ('test-identify_rows_dataframe.R:68:3'): edge case - unquoted vars works ──
  Error in ``[.data.table`(dt, , `:=`(incl, data.table::`%chin%`(unlist(.SD), matched_vals) %>% combine_fn(na.rm = TRUE)), by = "rid", .SDcols = vars)`: attempt access index 8/8 in VECTOR_ELT
  Backtrace:
      ▆
   1. ├─healthdb:::identify_rows(...) at test-identify_rows_dataframe.R:68:3
   2. └─healthdb:::identify_rows.data.frame(...)
   3.   ├─...[]
   4.   └─data.table:::`[.data.table`(...)
  ── Error ('test-identify_rows_dataframe.R:75:3'): edge case - vals in an external vector works ──
  Error in ``[.data.table`(dt, , `:=`(incl, data.table::`%chin%`(unlist(.SD), matched_vals) %>% combine_fn(na.rm = TRUE)), by = "rid", .SDcols = vars)`: attempt access index 8/8 in VECTOR_ELT
  Backtrace:
      ▆
   1. ├─healthdb:::identify_rows(...) at test-identify_rows_dataframe.R:75:3
   2. └─healthdb:::identify_rows.data.frame(...)
   3.   ├─...[]
   4.   └─data.table:::`[.data.table`(...)
  ── Error ('test-if_dates.R:41:3'): straight false due to no gap < within works ──
  Error in ``[.data.table`(overlap, , `:=`(N, .N), by = period_id)`: attempt access index 4/4 in VECTOR_ELT
  Backtrace:
      ▆
   1. ├─testthat::expect_false(if_dates(dates, 2, apart = 7, within = 30)) at test-if_dates.R:41:3
   2. │ └─testthat::quasi_label(enquo(object), label)
   3. │   └─rlang::eval_bare(expr, quo_get_env(quo))
   4. └─healthdb:::if_dates(dates, 2, apart = 7, within = 30)
   5.   ├─overlap[, `:=`(N, .N), by = period_id]
   6.   └─data.table:::`[.data.table`(overlap, , `:=`(N, .N), by = period_id)
  ── Error ('test-pool_case.R:45:3'): pool mixed works ───────────────────────────
  <dplyr:::mutate_error/rlang_error/error/condition>
  Error in `dplyr::mutate(., result = purrr::pmap(list(.data[["fn_call"]], .data[["src_labs"]], .data[["def_lab"]]), function(x, y, z) {     if (getOption("healthdb.verbose"))          rlang::inform(paste0("\nActions for definition ", z, " using source ", rlang::expr_deparse(with_data_expr[[y]]), ":\n"))     eval(x, envir = with_data_env) }, .progress = TRUE), result = purrr::pmap(list(.data[["result"]], .data[["def_lab"]], .data[["src_labs"]]), function(dat, def, src) {     dat %>% dplyr::mutate(def = def, src = src, .before = 1) }))`: i In argument: `result = purrr::pmap(...)`.
  Caused by error in `purrr::pmap()`:
  i In index: 1.
  Caused by error in `[.data.table`:
  ! attempt access index 8/8 in VECTOR_ELT
  ── Error ('test-pool_case.R:64:3'): edge case no date_var works ────────────────
  <dplyr:::mutate_error/rlang_error/error/condition>
  Error in `dplyr::mutate(., result = purrr::pmap(list(.data[["fn_call"]], .data[["src_labs"]], .data[["def_lab"]]), function(x, y, z) {     if (getOption("healthdb.verbose"))          rlang::inform(paste0("\nActions for definition ", z, " using source ", rlang::expr_deparse(with_data_expr[[y]]), ":\n"))     eval(x, envir = with_data_env) }, .progress = TRUE), result = purrr::pmap(list(.data[["result"]], .data[["def_lab"]], .data[["src_labs"]]), function(dat, def, src) {     dat %>% dplyr::mutate(def = def, src = src, .before = 1) }))`: i In argument: `result = purrr::pmap(...)`.
  Caused by error in `purrr::pmap()`:
  i In index: 1.
  Caused by error in `[.data.table`:
  ! attempt access index 8/8 in VECTOR_ELT
  ── Error ('test-pool_case.R:83:3'): edge case one date_var works ───────────────
  <dplyr:::mutate_error/rlang_error/error/condition>
  Error in `dplyr::mutate(., result = purrr::pmap(list(.data[["fn_call"]], .data[["src_labs"]], .data[["def_lab"]]), function(x, y, z) {     if (getOption("healthdb.verbose"))          rlang::inform(paste0("\nActions for definition ", z, " using source ", rlang::expr_deparse(with_data_expr[[y]]), ":\n"))     eval(x, envir = with_data_env) }, .progress = TRUE), result = purrr::pmap(list(.data[["result"]], .data[["def_lab"]], .data[["src_labs"]]), function(dat, def, src) {     dat %>% dplyr::mutate(def = def, src = src, .before = 1) }))`: i In argument: `result = purrr::pmap(...)`.
  Caused by error in `purrr::pmap()`:
  i In index: 1.
  Caused by error in `[.data.table`:
  ! attempt access index 8/8 in VECTOR_ELT
  ── Error ('test-pool_case.R:134:3'): pool multiple def works ───────────────────
  <dplyr:::mutate_error/rlang_error/error/condition>
  Error in `dplyr::mutate(., result = purrr::pmap(list(.data[["fn_call"]], .data[["src_labs"]], .data[["def_lab"]]), function(x, y, z) {     if (getOption("healthdb.verbose"))          rlang::inform(paste0("\nActions for definition ", z, " using source ", rlang::expr_deparse(with_data_expr[[y]]), ":\n"))     eval(x, envir = with_data_env) }, .progress = TRUE), result = purrr::pmap(list(.data[["result"]], .data[["def_lab"]], .data[["src_labs"]]), function(dat, def, src) {     dat %>% dplyr::mutate(def = def, src = src, .before = 1) }))`: i In argument: `result = purrr::pmap(...)`.
  Caused by error in `purrr::pmap()`:
  i In index: 1.
  Caused by error in `[.data.table`:
  ! attempt access index 8/8 in VECTOR_ELT
  
  [ FAIL 23 | WARN 2 | SKIP 6 | PASS 189 ]
  Error:
  ! Test failures.
  Execution halted