    ################
    ### Metadata ###
    ################

    # DATE LAST MODIFIED:
    # 19/09/2023

    # METADATA:
    if(FALSE) {
      title      <- 'BY-COVID WP5.2 Baseline Use Case: SARS-CoV-2 vaccine effectiveness - analytical pipeline'
      authors     <- list('Marjan Meurisse','Javier González-Galindo','Santiago Royo-Sierra','Francisco Estupiñán-Romero','Nina Van Goethem','Enrique Bernal-Delgado')
      version    <- '1.0.2'
      maintainer <- 'Marjan Meurisse'
      email      <- 'Marjan.Meurisse@sciensano.be'
      input      <- list('csv upload')
      output     <- list('1_DQA.html','2_validation.html','3_imputation.html','4_matching.html','5_descriptive.html','6_survival-analysis.html','results-survival-analysis-<country>.xlsx')
    }

    ################
    ### Overview ###
    ################

    # This analytical pipeline corresponds to BY-COVID WP5 T5.2 baseline use case on “SARS-CoV-2 Vaccine(s) effectiveness in preventing SARS-CoV-2 infection”

    # 0. General settings and loading of data
    #      -> Script: 0_global.R
    # 1. Data Quality Assessment (DQA)
    #      -> Script: 1_DQA.QMD
    #      -> Output: 1_DQA.html
    # 2. Validation
    #      -> Script: 2_validation.QMD
    #      -> Output: 2_validation.html
    # 3. Imputation of missing values
    #      -> Script: 3_imputation.QMD
    #      -> Output: 3_imputation.html
    # 4. Matching cases to controls (1:1) and assessing covariate balance after matching
    #      -> Script: 4_matching.QMD
    #      -> Output: 4_matching.html
    # 5. Descriptive analysis
    #      -> Script: 5_descriptives.R
    #      -> Output: 5_descriptive.html
    # 6. Survival analysis
    #      -> Script: 6_survival-analysis.R
    #      -> Output: 6_survival-analysis.html

    # 0. General settings and loading of data

    start_global_time <- Sys.time()

    source("./0_global.R")

    # Remove auxiliary database if it already exists
    if (file.exists(auxiliary_database_path)) {
      file.remove(auxiliary_database_path)
    }

    # Remove log file if it already exists
    if (file.exists(log_file_path)) {
      file.remove(log_file_path)
    }

    [1] TRUE

    # Load data
    tryCatch({
      f_load_data(create_db_tables = TRUE,
                   load_data = TRUE)
    }, error = function(err) {
      print(paste("MY ERROR:  ",err))
      knitr::knit_exit()
    })

## Data Quality Assessment

    # 1. Data Quality Assessment (DQA)

    start_DQA_time <- Sys.time()

    # Remove the file (html report) if it already exists
    if (file.exists("../output/1_DQA.html")) {
      file.remove("../output/1_DQA.html")
    }

    [1] TRUE

    # Render the quarto document
    tryCatch({
      quarto::quarto_render("./1_DQA.QMD", output_file = "1_DQA.html")
    }, error = function(err) {
      print(paste("MY ERROR:  ",err))
    })

    processing file: 1_DQA.QMD

      |
      |                                                                      |   0%
      |
      |..                                                                    |   3%
      ordinary text without R code

      |
      |....                                                                  |   6%
    label: metadata (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |......                                                                |   9%
      ordinary text without R code

      |
      |........                                                              |  12%
    label: unnamed-chunk-1 (with options)
    List of 1
     $ engine: chr "css"

      |
      |...........                                                           |  15%
      ordinary text without R code

      |
      |.............                                                         |  18%
    label: general settings (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |...............                                                       |  21%
      ordinary text without R code

      |
      |.................                                                     |  24%
    label: logging (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |...................                                                   |  27%
      ordinary text without R code

      |
      |.....................                                                 |  30%
    label: load data (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.......................                                               |  33%
      ordinary text without R code

      |
      |.........................                                             |  36%
    label: introduce (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |............................                                          |  39%
      ordinary text without R code

      |
      |..............................                                        |  42%
    label: dataset statistics (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |................................                                      |  45%
      ordinary text without R code

      |
      |..................................                                    |  48%
    label: variables (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |....................................                                  |  52%
      ordinary text without R code

      |
      |......................................                                |  55%
    label: classes (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |........................................                              |  58%
      ordinary text without R code

      |
      |..........................................                            |  61%
    label: missing data profile 1 (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.............................................                         |  64%
      ordinary text without R code

      |
      |...............................................                       |  67%
    label: missing data profile 2 (with options)
    List of 6
     $ results : chr "hide"
     $ fig.show: chr "hide"
     $ echo    : logi FALSE
     $ message : logi FALSE
     $ warning : logi FALSE
     $ error   : logi FALSE

      |
      |.................................................                     |  70%
      ordinary text without R code

      |
      |...................................................                   |  73%
    label: missing data profile 3 (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.....................................................                 |  76%
      ordinary text without R code

      |
      |.......................................................               |  79%
    label: alerts (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.........................................................             |  82%
      ordinary text without R code

      |
      |...........................................................           |  85%
    label: duplicates (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |..............................................................        |  88%
      ordinary text without R code

      |
      |................................................................      |  91%
    label: chunk (with options)
    List of 4
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE
     $ eval   : logi FALSE

      |
      |..................................................................    |  94%
      ordinary text without R code

      |
      |....................................................................  |  97%
    label: individual variables (with options)
    List of 4
     $ results: chr "asis"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |                                                                            output file: 1_DQA.knit.md

      |......................................................................| 100%
      ordinary text without R code

    Warning message:
    In do_once((if (is_R_CMD_check()) stop else warning)("The function xfun::isFALSE() will be deprecated in the future. Please ",  :
      The function xfun::isFALSE() will be deprecated in the future. Please consider using base::isFALSE(x) or identical(x, FALSE) instead.
    pandoc --output 1_DQA.html
      to: html
      standalone: true
      self-contained: true
      section-divs: true
      html-math-method: mathjax
      wrap: none
      default-image-extension: png

    metadata
      document-css: false
      link-citations: true
      date-format: long
      lang: en
      title: 'BY-COVID - WP5 - Baseline Use Case: SARS-CoV-2 vaccine effectiveness'
      subtitle: Data Quality Assessment (DQA)
      editor: visual
      always_allow_html: 'yes'
      title-block-banner: '#27445C'

    Output created: 1_DQA.html

    # Copy the file (html report) the 'output' folder
    # (exit the knit when the file is not successfully created)
    if(file.copy(from = "./1_DQA.html",
                    to = "../output/1_DQA.html") == TRUE) {
      file.remove("./1_DQA.html")
    } else {
      knitr::knit_exit()
    }

    [1] TRUE

## Validation

    # 2. Validation

    start_validation_time <- Sys.time()

    # Remove the file (html report) if it already exists
    if (file.exists("../output/2_validation.html")) {
      file.remove("../output/2_validation.html")
    }

    [1] TRUE

    # Render the quarto document
    tryCatch({
      quarto::quarto_render("./2_validation.QMD", output_file = "2_validation.html")
    }, error = function(err) {
      print(paste("MY ERROR:  ",err))
    })

    processing file: 2_validation.QMD

      |
      |                                                                      |   0%
      |
      |...                                                                   |   4%
      ordinary text without R code

      |
      |......                                                                |   8%
    label: metadata (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |........                                                              |  12%
      ordinary text without R code

      |
      |...........                                                           |  16%
    label: unnamed-chunk-1 (with options)
    List of 1
     $ engine: chr "css"

      |
      |..............                                                        |  20%
      ordinary text without R code

      |
      |.................                                                     |  24%
    label: general settings (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |....................                                                  |  28%
      ordinary text without R code

      |
      |......................                                                |  32%
    label: logging (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.........................                                             |  36%
      ordinary text without R code

      |
      |............................                                          |  40%
    label: load data (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |...............................                                       |  44%
      ordinary text without R code

      |
      |..................................                                    |  48%
    label: validation rules (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |....................................                                  |  52%
      ordinary text without R code

      |
      |.......................................                               |  56%
    label: validation table (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |..........................................                            |  60%
      ordinary text without R code

      |
      |.............................................                         |  64%
    label: validation plot 1 (with options)
    List of 5
     $ results : chr "hide"
     $ fig.show: chr "hide"
     $ message : logi FALSE
     $ warning : logi FALSE
     $ error   : logi FALSE

      |
      |................................................                      |  68%
      ordinary text without R code

      |
      |..................................................                    |  72%
    label: validation plot 2 (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.....................................................                 |  76%
      ordinary text without R code

      |
      |........................................................              |  80%
    label: violating essential rules (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |...........................................................           |  84%
      ordinary text without R code

      |
      |..............................................................        |  88%
    label: save violated (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |................................................................      |  92%
      ordinary text without R code

      |
      |...................................................................   |  96%
    label: print violating rules (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |......................................................................| 100%
      ordinary text without R code

    output file: 2_validation.knit.md

    Warning message:
    In do_once((if (is_R_CMD_check()) stop else warning)("The function xfun::isFALSE() will be deprecated in the future. Please ",  :
      The function xfun::isFALSE() will be deprecated in the future. Please consider using base::isFALSE(x) or identical(x, FALSE) instead.
    pandoc --output 2_validation.html
      to: html
      standalone: true
      self-contained: true
      section-divs: true
      html-math-method: mathjax
      wrap: none
      default-image-extension: png

    metadata
      document-css: false
      link-citations: true
      date-format: long
      lang: en
      title: 'BY-COVID - WP5 - Baseline Use Case: SARS-CoV-2 vaccine effectiveness assessment'
      subtitle: Validation
      editor: visual
      always_allow_html: 'yes'
      title-block-banner: '#27445C'

    Output created: 2_validation.html

    # Copy the file (html report) the 'output' folder
    # (exit the knit when the file is not successfully created)
    if(file.copy(from = "./2_validation.html",
                    to = "../output/2_validation.html") == TRUE) {
      file.remove("./2_validation.html")
    } else {
      knitr::knit_exit()
    }

    [1] TRUE

## Imputation of missing values

    # 3. Imputation of missing values

    start_imputation_time <- Sys.time()

    # Remove the file (html report) if it already exists
    if (file.exists("../output/3_imputation.html")) {
      file.remove("../output/3_imputation.html")
    }

    [1] TRUE

    # Render the quarto document
    tryCatch({
      quarto::quarto_render("./3_imputation.QMD", output_file = "3_imputation.html")
    }, error = function(err) {
      print(paste("MY ERROR:  ",err))
    })

    processing file: 3_imputation.QMD

      |
      |                                                                      |   0%
      |
      |..                                                                    |   3%
      ordinary text without R code

      |
      |.....                                                                 |   7%
    label: metadata (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.......                                                               |  10%
      ordinary text without R code

      |
      |..........                                                            |  14%
    label: general settings (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |............                                                          |  17%
      ordinary text without R code

      |
      |..............                                                        |  21%
    label: logging (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.................                                                     |  24%
      ordinary text without R code

      |
      |...................                                                   |  28%
    label: load data (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |......................                                                |  31%
      ordinary text without R code

      |
      |........................                                              |  34%
    label: missing values map (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |...........................                                           |  38%
      ordinary text without R code

      |
      |.............................                                         |  41%
    label: missing data matrix (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |...............................                                       |  45%
      ordinary text without R code

      |
      |..................................                                    |  48%
    label: variable status 1 (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |....................................                                  |  52%
      ordinary text without R code

      |
      |.......................................                               |  55%
    label: variable status 2 (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.........................................                             |  59%
      ordinary text without R code

      |
      |...........................................                           |  62%
    label: save variable status (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |..............................................                        |  66%
      ordinary text without R code

      |
      |................................................                      |  69%
    label: listwise deletion (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |...................................................                   |  72%
      ordinary text without R code

      |
      |.....................................................                 |  76%
    label: imputation (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |........................................................              |  79%
      ordinary text without R code

      |
      |..........................................................            |  83%
    label: imputation process print (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |............................................................          |  86%
      ordinary text without R code

      |
      |...............................................................       |  90%
    label: plot imputation (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.................................................................     |  93%
      ordinary text without R code

      |
      |....................................................................  |  97%
    label: print listwise deletion (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |......................................................................| 100%
      ordinary text without R code

    output file: 3_imputation.knit.md

    Warning message:
    In do_once((if (is_R_CMD_check()) stop else warning)("The function xfun::isFALSE() will be deprecated in the future. Please ",  :
      The function xfun::isFALSE() will be deprecated in the future. Please consider using base::isFALSE(x) or identical(x, FALSE) instead.
    pandoc --output 3_imputation.html
      to: html
      standalone: true
      self-contained: true
      section-divs: true
      html-math-method: mathjax
      wrap: none
      default-image-extension: png

    metadata
      document-css: false
      link-citations: true
      date-format: long
      lang: en
      title: 'BY-COVID - WP5 - Baseline Use Case: SARS-CoV-2 vaccine effectiveness assessment'
      subtitle: Imputation of missing values
      editor: visual
      always_allow_html: 'yes'
      title-block-banner: '#27445C'

    Output created: 3_imputation.html

    # Copy the file (html report) the 'output' folder
    # (exit the knit when the file is not successfully created)
    if(file.copy(from = "./3_imputation.html",
                    to = "../output/3_imputation.html") == TRUE) {
      file.remove("./3_imputation.html")
    } else {
      knitr::knit_exit()
    }

    [1] TRUE

## Matching

    # 4. Matching cases to controls (1:1) and assessing covariate balance after matching

    start_matching_time <- Sys.time()

    # Remove the file (html report) if it already exists
    if (file.exists("../output/4_matching.html")) {
      file.remove("../output/4_matching.html")
    }

    [1] TRUE

    # Render the quarto document
    tryCatch({
      quarto::quarto_render("./4_matching.QMD", output_file = "4_matching.html")
    }, error = function(err) {
      print(paste("MY ERROR:  ",err))
    })

    processing file: 4_matching.QMD

      |
      |                                                                      |   0%
      |
      |..                                                                    |   3%
      ordinary text without R code

      |
      |.....                                                                 |   6%
    label: metadata (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.......                                                               |  10%
      ordinary text without R code

      |
      |.........                                                             |  13%
    label: general settings (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |...........                                                           |  16%
      ordinary text without R code

      |
      |..............                                                        |  19%
    label: logging (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |................                                                      |  23%
      ordinary text without R code

      |
      |..................                                                    |  26%
    label: matching (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |....................                                                  |  29%
      ordinary text without R code

      |
      |.......................                                               |  32%
    label: load data (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.........................                                             |  35%
      ordinary text without R code

      |
      |...........................                                           |  39%
    label: matchit prior (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.............................                                         |  42%
      ordinary text without R code

      |
      |................................                                      |  45%
    label: matchit after (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |..................................                                    |  48%
      ordinary text without R code

      |
      |....................................                                  |  52%
    label: SMD prior matching (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |......................................                                |  55%
      ordinary text without R code

      |
      |.........................................                             |  58%
    label: SMD prior matching plot (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |...........................................                           |  61%
      ordinary text without R code

      |
      |.............................................                         |  65%
    label: SMD prior matching plot 2 (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |...............................................                       |  68%
      ordinary text without R code

      |
      |..................................................                    |  71%
    label: SMD after matching (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |....................................................                  |  74%
      ordinary text without R code

      |
      |......................................................                |  77%
    label: SMD after matching plot (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |........................................................              |  81%
      ordinary text without R code

      |
      |...........................................................           |  84%
    label: SMD after matching plot 2 (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.............................................................         |  87%
      ordinary text without R code

      |
      |...............................................................       |  90%
    label: plot ps before (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.................................................................     |  94%
      ordinary text without R code

      |
      |....................................................................  |  97%
    label: plot ps after (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |......................................................................| 100%
      ordinary text without R code

    output file: 4_matching.knit.md

    Warning messages:
    1: In do_once((if (is_R_CMD_check()) stop else warning)("The function xfun::isFALSE() will be deprecated in the future. Please ",  :
      The function xfun::isFALSE() will be deprecated in the future. Please consider using base::isFALSE(x) or identical(x, FALSE) instead.
    2: In .Internal(gc(verbose, reset, full)) :
      closing unused connection 8 (<-kubernetes.docker.internal:11609)
    3: In .Internal(gc(verbose, reset, full)) :
      closing unused connection 7 (<-kubernetes.docker.internal:11609)
    4: In .Internal(gc(verbose, reset, full)) :
      closing unused connection 6 (<-kubernetes.docker.internal:11609)
    5: In .Internal(gc(verbose, reset, full)) :
      closing unused connection 5 (<-kubernetes.docker.internal:11609)
    pandoc --output 4_matching.html
      to: html
      standalone: true
      self-contained: true
      section-divs: true
      html-math-method: mathjax
      wrap: none
      default-image-extension: png

    metadata
      document-css: false
      link-citations: true
      date-format: long
      lang: en
      title: 'BY-COVID - WP5 - Baseline Use Case: COVID-19 vaccine effectiveness assessment'
      subtitle: 'Matching cases to controls (1:1) and assessing covariate balance after matching'
      editor: visual
      always_allow_html: 'yes'
      title-block-banner: '#27445C'

    Output created: 4_matching.html

    # Copy the file (html report) the 'output' folder
    # (exit the knit when the file is not successfully created)
    if(file.copy(from = "./4_matching.html",
                    to = "../output/4_matching.html") == TRUE) {
      file.remove("./4_matching.html")
    } else {
      knitr::knit_exit()
    }

    [1] TRUE

## Descriptive analyses

    # 5. Descriptive analysis

    start_descriptive_time <- Sys.time()

    # Remove the file (html report) if it already exists
    if (file.exists("../output/5_descriptive.html")) {
      file.remove("../output/5_descriptive.html")
    }

    [1] TRUE

    # Render the quarto document
    tryCatch({
      quarto::quarto_render("./5_descriptives.QMD", output_file = "5_descriptive.html")
    }, error = function(err) {
      print(paste("MY ERROR:  ",err))
    })

    processing file: 5_descriptives.QMD

      |
      |                                                                      |   0%
      |
      |.                                                                     |   2%
      ordinary text without R code

      |
      |...                                                                   |   4%
    label: metadata (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |....                                                                  |   6%
      ordinary text without R code

      |
      |.....                                                                 |   8%
    label: general settings (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.......                                                               |  10%
      ordinary text without R code

      |
      |........                                                              |  12%
    label: logging (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |..........                                                            |  14%
      ordinary text without R code

      |
      |...........                                                           |  16%
    label: load data (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |............                                                          |  18%
      ordinary text without R code

      |
      |..............                                                        |  20%
    label: periods (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |...............                                                       |  22%
      ordinary text without R code

      |
      |................                                                      |  24%
    label: create consort graph (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |..................                                                    |  25%
      ordinary text without R code

      |
      |...................                                                   |  27%
    label: plot consort graph (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.....................                                                 |  29%
      ordinary text without R code

      |
      |......................                                                |  31%
    label: table 1 un-matched (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.......................                                               |  33%
      ordinary text without R code

      |
      |.........................                                             |  35%
    label: table 1 matched (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |..........................                                            |  37%
      ordinary text without R code

      |
      |...........................                                           |  39%
    label: plot vaccination over time (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.............................                                         |  41%
      ordinary text without R code

      |
      |..............................                                        |  43%
    label: plot vaccination over time by vaccination schedule (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |................................                                      |  45%
      ordinary text without R code

      |
      |.................................                                     |  47%
    label: plot vaccination over time by vaccination schedule 2 (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |..................................                                    |  49%
      ordinary text without R code

      |
      |....................................                                  |  51%
    label: tables (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.....................................                                 |  53%
       inline R code fragments

      |
      |......................................                                |  55%
    label: print table un-matched start population (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |........................................                              |  57%
       inline R code fragments

      |
      |.........................................                             |  59%
    label: print table un-matched eligible population (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |...........................................                           |  61%
       inline R code fragments

      |
      |............................................                          |  63%
    label: print table matched population (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.............................................                         |  65%
       inline R code fragments

      |
      |...............................................                       |  67%
    label: survival in un-matched population (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |................................................                      |  69%
      ordinary text without R code

      |
      |.................................................                     |  71%
    label: survival not matched and simple model (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |...................................................                   |  73%
      ordinary text without R code

      |
      |....................................................                  |  75%
    label: summary survival not matched and simple model (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |......................................................                |  76%
      ordinary text without R code

      |
      |.......................................................               |  78%
    label: survival plot not matched and simple model (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |........................................................              |  80%
      ordinary text without R code

      |
      |..........................................................            |  82%
    label: cumulative events plot not matched and simple model (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |...........................................................           |  84%
      ordinary text without R code

      |
      |............................................................          |  86%
    label: survival cumulative events table (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |..............................................................        |  88%
      ordinary text without R code

      |
      |...............................................................       |  90%
    label: survival not matched and complex model (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.................................................................     |  92%
      ordinary text without R code

      |
      |..................................................................    |  94%
    label: summary survival not matched and complex model (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |...................................................................   |  96%
      ordinary text without R code

      |
      |..................................................................... |  98%
    label: survival plot not matched and complex model (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |......................................................................| 100%
      ordinary text without R code

    output file: 5_descriptives.knit.md

    Warning message:
    In do_once((if (is_R_CMD_check()) stop else warning)("The function xfun::isFALSE() will be deprecated in the future. Please ",  :
      The function xfun::isFALSE() will be deprecated in the future. Please consider using base::isFALSE(x) or identical(x, FALSE) instead.
    pandoc --output 5_descriptive.html
      to: html
      standalone: true
      self-contained: true
      section-divs: true
      html-math-method: mathjax
      wrap: none
      default-image-extension: png

    metadata
      document-css: false
      link-citations: true
      date-format: long
      lang: en
      title: 'BY-COVID - WP5 - Baseline Use Case: COVID-19 vaccine effectiveness assessment'
      subtitle: Descriptive analyses
      editor: visual
      always_allow_html: 'yes'
      title-block-banner: '#27445C'

    [33mWARNING: Unable to parse table from raw html block: skipping.
    [39m[33mWARNING: Unable to parse table from raw html block: skipping.
    [39mOutput created: 5_descriptive.html

    # Copy the file (html report) the 'output' folder
    # (exit the knit when the file is not successfully created)
    if(file.copy(from = "./5_descriptive.html",
                    to = "../output/5_descriptive.html") == TRUE) {
      file.remove("./5_descriptive.html")
    } else {
      knitr::knit_exit()
    }

    [1] TRUE

## Survival analysis

    # 6. Survival analysis

    start_survival_time <- Sys.time()

    # Remove the file (html report) if it already exists
    if (file.exists("../output/6_survival-analysis.html")) {
      file.remove("../output/6_survival-analysis.html")
    }

    [1] TRUE

    # Render the quarto document
    tryCatch({
      quarto::quarto_render("./6_survival-analysis.QMD", output_file = "6_survival-analysis.html")
    }, error = function(err) {
      print(paste("MY ERROR:  ",err))
    })

    processing file: 6_survival-analysis.QMD

      |
      |                                                                      |   0%
      |
      |.                                                                     |   1%
      ordinary text without R code

      |
      |..                                                                    |   3%
    label: metadata (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |...                                                                   |   4%
      ordinary text without R code

      |
      |....                                                                  |   5%
    label: general settings (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.....                                                                 |   6%
      ordinary text without R code

      |
      |.....                                                                 |   8%
    label: logging (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |......                                                                |   9%
      ordinary text without R code

      |
      |.......                                                               |  10%
    label: load data (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |........                                                              |  12%
      ordinary text without R code

      |
      |.........                                                             |  13%
    label: survival (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |..........                                                            |  14%
      ordinary text without R code

      |
      |...........                                                           |  16%
    label: survival plot (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |............                                                          |  17%
      ordinary text without R code

      |
      |.............                                                         |  18%
    label: survival plot 2 (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |..............                                                        |  19%
      ordinary text without R code

      |
      |...............                                                       |  21%
    label: cumulative events plot (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |...............                                                       |  22%
      ordinary text without R code

      |
      |................                                                      |  23%
    label: cumulative events plot 2 (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.................                                                     |  25%
      ordinary text without R code

      |
      |..................                                                    |  26%
    label: x-time survival (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |...................                                                   |  27%
      ordinary text without R code

      |
      |....................                                                  |  29%
    label: median survival time (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.....................                                                 |  30%
      ordinary text without R code

      |
      |......................                                                |  31%
    label: coxph HR (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.......................                                               |  32%
      ordinary text without R code

      |
      |........................                                              |  34%
    label: hazard ratio (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.........................                                             |  35%
      ordinary text without R code

      |
      |.........................                                             |  36%
    label: coxph model fit (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |..........................                                            |  38%
      ordinary text without R code

      |
      |...........................                                           |  39%
    label: rmst2 (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |............................                                          |  40%
      ordinary text without R code

      |
      |.............................                                         |  42%
    label: RMST and RMTL (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |..............................                                        |  43%
      ordinary text without R code

      |
      |...............................                                       |  44%
    label: average treatment effect (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |................................                                      |  45%
      ordinary text without R code

      |
      |.................................                                     |  47%
    label: survival plot by vaccination schedule (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |..................................                                    |  48%
      ordinary text without R code

      |
      |...................................                                   |  49%
    label: survival plot by vaccination schedule 2 (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |...................................                                   |  51%
      ordinary text without R code

      |
      |....................................                                  |  52%
    label: cumulative incidence by vaccination schedule (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.....................................                                 |  53%
      ordinary text without R code

      |
      |......................................                                |  55%
    label: cumulative incidence by vaccination schedule 2 (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.......................................                               |  56%
      ordinary text without R code

      |
      |........................................                              |  57%
    label: coxph HR by vaccination schedule (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.........................................                             |  58%
      ordinary text without R code

      |
      |..........................................                            |  60%
    label: hazard ratio by vaccination schedule (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |...........................................                           |  61%
      ordinary text without R code

      |
      |............................................                          |  62%
    label: coxph model by vaccination schedule fit (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.............................................                         |  64%
      ordinary text without R code

      |
      |.............................................                         |  65%
    label: rmst2 by vaccination schedele (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |..............................................                        |  66%
      ordinary text without R code

      |
      |...............................................                       |  68%
    label: RMST and RMTL by vaccination schedele (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |................................................                      |  69%
      ordinary text without R code

      |
      |.................................................                     |  70%
    label: average treatment effect by vaccination schedele (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |..................................................                    |  71%
      ordinary text without R code

      |
      |...................................................                   |  73%
    label: survival plot by residence area (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |....................................................                  |  74%
      ordinary text without R code

      |
      |.....................................................                 |  75%
    label: survival plot by residence area 2 (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |......................................................                |  77%
      ordinary text without R code

      |
      |.......................................................               |  78%
    label: cumulative incidence by residence area (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.......................................................               |  79%
      ordinary text without R code

      |
      |........................................................              |  81%
    label: cumulative incidence by residence area 2 (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.........................................................             |  82%
      ordinary text without R code

      |
      |..........................................................            |  83%
    label: coxph HR by residence area (with options)
    List of 4
     $ results: chr "hide"
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |...........................................................           |  84%
      ordinary text without R code

      |
      |............................................................          |  86%
    label: hazard ratio by residence area (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.............................................................         |  87%
      ordinary text without R code

      |
      |..............................................................        |  88%
    label: coxph model by residence area fit (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |...............................................................       |  90%
      ordinary text without R code

      |
      |................................................................      |  91%
    label: rmst2 by residence area (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |.................................................................     |  92%
      ordinary text without R code

      |
      |.................................................................     |  94%
    label: RMST and RMTL by residence area (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |..................................................................    |  95%
      ordinary text without R code

      |
      |...................................................................   |  96%
    label: average treatment effect by residence area (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |....................................................................  |  97%
      ordinary text without R code

      |
      |..................................................................... |  99%
    label: saving results for meta-analysis (with options)
    List of 3
     $ message: logi FALSE
     $ warning: logi FALSE
     $ error  : logi FALSE

      |
      |......................................................................| 100%
      ordinary text without R code

    output file: 6_survival-analysis.knit.md

    Warning message:
    In do_once((if (is_R_CMD_check()) stop else warning)("The function xfun::isFALSE() will be deprecated in the future. Please ",  :
      The function xfun::isFALSE() will be deprecated in the future. Please consider using base::isFALSE(x) or identical(x, FALSE) instead.
    WARNING: Warning: diff of engine output timed out. No source lines will be available.
    pandoc --output 6_survival-analysis.html
      to: html
      standalone: true
      self-contained: true
      section-divs: true
      html-math-method: mathjax
      wrap: none
      default-image-extension: png

    metadata
      document-css: false
      link-citations: true
      date-format: long
      lang: en
      title: 'BY-COVID - WP5 - Baseline Use Case: COVID-19 vaccine effectiveness assessment'
      subtitle: Survival analysis
      editor: visual
      always_allow_html: 'yes'
      title-block-banner: '#27445C'

    Output created: 6_survival-analysis.html

    # Copy the file (html report) the 'output' folder
    # (exit the knit when the file is not successfully created)
    if(file.copy(from = "./6_survival-analysis.html",
                    to = "../output/6_survival-analysis.html") == TRUE) {
      file.remove("./6_survival-analysis.html")
      # Copy the results for meta-analysis (xlsx file)
      file_xlsx <- grep(".xlsx", list.files(path="./", full.names = TRUE, recursive = TRUE), value = TRUE)
      file.copy(from = file_xlsx,
                    to = paste0("../output/",sub('.*./', '', file_xlsx)))
      file.remove(file_xlsx)
      # Copy the results for meta-analysis (rds file)
      file_rds <- grep(".rds", list.files(path="./", full.names = TRUE, recursive = TRUE), value = TRUE)
      file.copy(from = file_rds,
                    to = paste0("../output/",sub('.*./', '', file_rds)))
      file.remove(file_rds)
    } else {
      knitr::knit_exit()
    }

    logical(0)

    # Assess the runtime

    info(logger,
      paste0("
    ========================================================================================
    ",
    "Runtime","
    ",
    "========================================================================================
      "))

    end_time <- Sys.time()

    info(logger_simple, paste0("Overall runtime: ", round(difftime(end_time,start_global_time)[[1]],2), " ", units(difftime(end_time,start_global_time))))
    info(logger_simple, paste0("Runtime 0_global.R: ", round(difftime(start_DQA_time,start_global_time)[[1]],2), " ", units(difftime(start_DQA_time,start_global_time))))
    info(logger_simple, paste0("Runtime 1_DQA.QMD: ", round(difftime(start_validation_time,start_DQA_time)[[1]],2), " ", units(difftime(start_validation_time,start_DQA_time))))
    info(logger_simple, paste0("Runtime 2_validation.QMD: ", round(difftime(start_imputation_time,start_validation_time)[[1]],2), " ", units(difftime(start_imputation_time,start_validation_time))))
    info(logger_simple, paste0("Runtime 3_imputation.QMD: ", round(difftime(start_matching_time,start_imputation_time)[[1]],2), " ", units(difftime(start_matching_time,start_imputation_time))))
    info(logger_simple, paste0("Runtime 4_matching.QMD: ", round(difftime(start_descriptive_time,start_matching_time)[[1]],2), " ", units(difftime(start_descriptive_time,start_matching_time))))
    info(logger_simple, paste0("Runtime 5_descriptives.QMD: ", round(difftime(start_survival_time,start_descriptive_time)[[1]],2), " ", units(difftime(start_survival_time,start_descriptive_time))))
    info(logger_simple, paste0("Runtime 6_survival-analysis.QMD: ", round(difftime(end_time,start_survival_time)[[1]],2), " ", units(difftime(end_time,start_survival_time))))