pandoc's markdown "table" in rmarkdown-2.0 cheat sheet doesn't work with tex markdown

I have an error in rmarkdown using Pandoc's Markdown "tables" as shown in rmarkdown-2.0 cheat sheet with pdf markdown which doesn't appear html or word markdown. What am I doing wrong? How do I fix it.

my session information is:

sessionInfo()

R version 3.6.2 (2019-12-12)

Platform: x86_64-w64-mingw32/x64 (64-bit)

Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:

[1] LC_COLLATE=English_United States.1252

[2] LC_CTYPE=English_United States.1252

[3] LC_MONETARY=English_United States.1252

[4] LC_NUMERIC=C

[5] LC_TIME=English_United States.1252

attached base packages:

[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached):

[1] compiler_3.6.2 magrittr_1.5 tools_3.6.2 htmltools_0.4.0

[5] yaml_2.2.0 Rcpp_1.0.3 stringi_1.4.5 rmarkdown_2.0

[9] knitr_1.27 stringr_1.4.0 xfun_0.12 digest_0.6.23

[13] rlang_0.4.2 evaluate_0.14

The following code works fine with html, and word markdown:


title: "An All Possible Models Procedure"
author: "Peter B. Mandeville"
date: "r format(Sys.time(),'%I:%M %p %d %B %Y')"
output:
pdf_document :
latex_engine : pdflatex #xelatex
html_document:
df_print: paged
toc: yes
toc_float: true
number_sections: true
word_document:
toc: yes

knitr::opts_chunk$set(echo = TRUE)

R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)

Including Plots

You can also embed plots, for example:

plot(pressure)

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.


Abbreviations

This is a test

Abbreviation Meaning
AIC Akaike's Information Criterion
B
BIC Bayesian Information Criterion
Cp Mallows C_p
CV Cross-Validation
D Discrimination index — likelihood ratio χ2 divided by the sample size
Dxy Dxy:Somers’ rank correlation between predicted probability that Y = 1 vs. the binary Y values. This equals 2(C − 0.5) where C is the “ROC Area or concordance probability
EDA Exploratory Data Analysis

However, it produces an error in pdf markdown

This is the error message:

output file: test-error2.knit.md

! Missing number, treated as zero.

\protect
l.156 ...nter}\rule{0.5\linewidth}{\linethickness}
\end{center}

Error: LaTeX failed to compile test-error2.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See test-error2.log for more info.
Execution halted

What am I doing wrong? How do I fix it?

Thank you very much.

pbm

Here's what I found

---
title: "table"
output:
  pdf_document:
    latex_engine : pdflatex
--- 

"```"{r, echo=FALSE}
knitr::opts_chunk$set(echo = TRUE)
.# kable_table <- knitr::kable(mtcars[1:5,]) # undefined control seq
xtable_table <- xtable::xtable(mtcars[1:5,])
"```"

"`r xtable_table`"

Thank you technocrat, but the problem persists. I include the same reprex reformatted.

---
title: "test"
author: "pbm"
date: "`r format(Sys.time(),'%I:%M %p %d %B %Y')`"
output: 
  pdf_document :
    latex_engine : pdflatex
  word_document:
    toc: yes
  html_document:
    df_print: paged
    toc: yes
    toc_float: true
    number_sections: true
---

```{r setup,include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

Required Packages

  library(tinytex)
  library(knitr)
  library(kableExtra)
  library(xtable)

Dataframe

Abbreviation <- c("AIC","B","BIC","Cp","CV","D","Dxy","EDA") 
Meaning <- c(
  "Akaike's Information Criterion",
  "",
  "Bayesian Information Criterion",
  "Mallows $C_p$",
  "Cross-Validation",
  "Discrimination index — likelihood ratio χ2 divided by the sample size", 
  "Dxy:Somers’ rank correlation between predicted probability that Y = 1 vs. the binary Y values. This equals $2(C − 0.5)$ where C is the “ROC Area or concordance probability",
  "Exploratory Data Analysis"
)
df <- data.frame(Abbreviation,Meaning)
dim(df)
class(df)
df

## kable

```{r}
kable(df)

Runs with "Run Current Chunk" and "Knit to HTML" but not with "Knit to PDF".

xtable

xtable(df)

Runs with "Run Current Chunk" and "Knit to HTML" but not with "Knit to PDF".

What am I doing wrong?

How do I fix it?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.