0

I'm trying to build a single .Rmd file that produces a markdown table (for github) and a pdf table (as a file) that avoids the "Table 1:" annoyance in the caption. I've tried to adapt the solution described in How to suppress automatic table name and number in an .Rmd file using xtable or knitr::kable?, but I think I am polluting the YAML commands. My code below builds the github compatible markdown, but the pdf is not written. Are two outputs not supported or is there a YAML tweak? Thank you.

     ---
     title: "huh"
     output: 
      github_document: default
      pdf_document: default

     header-includes: 
       - \usepackage{caption}
       - \captionsetup[table]{labelformat=empty}

     always_allow_html: true
     ---

     ```{r makeStats, echo=FALSE, include=TRUE, results='asis', message=F, warning=T}

     library(tidyverse)
     library(dplyr)
     library(knitr)
     library(kableExtra)

     huh.tbl <- tribble(~period, ~cohens.d, ~SNHmean, 
                      "week 23", 0.4, 0.6)

     ````

     ```{r pdfTable, echo=FALSE, include=TRUE, results='asis', message=F, warning=T}

     knitr::kable(huh.tbl, 
      caption="please don't mess with me",
      col.names = linebreak(c("seasonal\nperiod", 
                    "Cohen's d\neffect size", 
                    "SNH\nmean)")),
      escape=FALSE,
      align = "lcc",
      row.names=FALSE,
      format="latex",
      booktabs=TRUE ) %>%

      kableExtra::column_spec(1,width = "20%") %>%
      kableExtra::column_spec(2,width = "20%") %>%
      kableExtra::column_spec(3,width = "20%") %>%

      kableExtra::save_kable(paste("/Users/xxx/Desktop", 
                                   "markdownTable", 
                                   ".pdf", 
                                   sep=""))

      ````


      ```{r markdownTable, echo=FALSE, include=TRUE, results='asis', message=F, warning=T}

      knitr::kable(huh.tbl, 
        caption="please don't mess with me",
        col.names = c("seasonal<br/>period", 
                    "Cohen's d<br/>effect size", 
                    "SNH<br/>mean"),
        escape=FALSE,
        full_width=TRUE,
        font_size=10,
        align = "lcc") %>%

      kableExtra::column_spec(1,width = "20%") %>%
      kableExtra::column_spec(2,width = "20%") %>%
      kableExtra::column_spec(3,width = "20%")

      ````
Phil
  • 7,287
  • 3
  • 36
  • 66
Cord
  • 196
  • 11
  • As far as I know, the answer is no. But why not just make two different .Rmd files? – Phil Nov 05 '20 at 18:17
  • The pdf content will be part of a (hopefully) published academic paper. I'm relying on github to enable the provision of both an additional layer of detail around tables and figures plus real transparency for the data and code that supports the conclusions of the paper. Different Rmd files are an option, but the transparency score will take a hit. – Cord Nov 06 '20 at 14:40

0 Answers0