1

I am trying generate automated reports using rmarkdown, and final output expected is pdf. However, when I run the script the resulting .Rmd file is okay, but the resulting .pdf file does not show the table. It just shows the table as a list of values. However, if I open the .Rmd file in RStudio, and use the kint button, I get a correctly formatted pdf file. Has anyone seen this behaviour before? am I missing something?

    ---
    title: "RUO"
    author: "Me"
    date: "`r format(Sys.Date(), '%B %d, %Y')`"
    always_allow_html: true
    output:
      pdf_document:
      df_print: kable
      keep_tex: true
      latex_engine: lualatex
    header-includes:
      - \usepackage{graphicx}
      - \usepackage{fancyhdr}
      - \usepackage{float}
      - \usepackage{colortbl}
      - \usepackage[para,flushleft]{threeparttable}
      - \usepackage{fontspec}
      - \setmainfont{Raleway}
      - \AtBeginDocument{\let\maketitle\relax}
    classoption:
      - twocolumn
    ---
    \fancypagestyle{plain}{}
    \pagestyle{fancy}
    \addtolength{\headheight}{1.0cm}
    \rhead{Name: John Doe\\Sex: Male\\DoB: 01.01.01\\Lab \#: XXXXXXXX\\MRN \#: XXXXXXXX}

    ```{r setup, warning = FALSE, message = FALSE, echo = FALSE}
    knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
    library(tidyverse)
    library(stringi)
    library(DESeq2)
    library(kableExtra)
    ```

    ## This section is for Research Use Only

    ### Expression Table

    ```{r ExpTable}
    df <- data.frame(cbind("gene_name" = c("AAA", "BBB", "CCC"), 
                       "z-score" = c(-2, 2, 3)))
    df %>%
      setNames(c("Gene Name", "Z-score")) %>%
      as.data.frame() %>%
      # as_tibble() %>%
      knitr::kable(booktabs = T) %>%
      kableExtra::kable_styling(latex_options = c("hold_position", "striped")) # %>%
      # kableExtra::column_spec(2, width = "3 cm")
    ```


    \vfill


    ### Methodology

    Some Description 

    ### Comments and Limitations

    Disclosures.

    \clearpage

This code is the minimal example. When you use something like:

    Rscript -e "library('knitr'); knitr::knit('filename.Rmd')"

The table does not render, but opening the same file in RStudio, renders is correctly.


UPDATE:

I realized after some more digging, that this is a un-reported bug (probably). If you render a rmarkdown with a table to pdf, then it will usually render correctly. But sometimes, the table is rendered as a list in the first render, and if you then render the same .Rmd to pdf, the table is rendered and correctly reformatted. So if you render the same file twice, the second time all the tables are correctly rendered. This happens more frequently if the only thing your file has a single table.

Sam
  • 7,922
  • 16
  • 47
  • 62

0 Answers0