Welcome to TeX.SE. Don't use square brackets [] in your math expression. Use braces {} only. You wrote: $\xrightarrow[\text{sample text}]$. It should be: $\xrightarrow{\text{sample text}}$.
Edit: Updated to show the use of \Bracket and \Set from the braket package.

---
title: "Title"
author: "Me"
header-includes:
- \usepackage{array}
- \usepackage{booktabs}
- \usepackage{mathtools}
- \usepackage{braket}
output:
pdf_document:
keep_tex: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
\hrule <!-- draw a horizontal line -->
We can write in markdown and add content that uses LaTeX syntax and \LaTeX\ packages to format our document.
Using mathtools package
$\xrightarrow{\text{sample text}}$
<br> <!-- add space, like \bigskip % - this is a comment -->
Using array, booktabs and braket packages
\begingroup
\renewcommand*{\arraystretch}{1.7}
\setlength{\tabcolsep}{10pt}
\begin{tabular}{@{}>{\footnotesize}r>{$\displaystyle}l<{$}@{}}
\toprule
\verb+\Braket{ \phi | \frac{\partial^2}{\partial t^2} | \psi }+ & \Braket{ \phi | \frac{\partial^2}{\partial t^2} | \psi } \
\verb+\Set{ x\in\mathbf{R}^2 | 0<{|x|}<5 }+ & \Set{ x\in\mathbf{R}^2 | 0<{|x|}<5 } \
\bottomrule
\end{tabular}
\endgroup
We can do math
result <- 1 + 2
result
[]in your math formula. Replace with{}and your code works. – Ross Sep 16 '20 at 14:05markdown, which is converted toLaTeXto render thepdf. As such, it begins with aYAMLheader, not\documentclass. The OP has given enough code and information to identify the problem. – Ross Sep 16 '20 at 15:07