Sort of! Here’s a description of the process starting with rmarkdown:render() (the more typical starting point, and what the RStudio knit button is running under the hood):
When you run render , R Markdown feeds the .Rmd file to knitr ⧉, which executes all of the code chunks and creates a new markdown (.md) document which includes the code and its output.
The markdown file generated by knitr is then processed by pandoc ⧉ which is responsible for creating the finished format.
(source)
Note that running rmarkdown::render() yourself isn’t quite the same as using the knit button, unless you make sure to start a new R session first — see here: https://bookdown.org/yihui/rmarkdown/compile.html
Edited to add:
Maybe double check that your YAML indentation is correct in the actual file? It doesn’t look quite right in your pasted example above, but that could be a copy-paste artifact. YAML is very picky about indentation, and indentation problems are the most common source of this sort of issue. Correct indentation for this case (from the RMarkdown book):
---
title: "Habits"
output:
pdf_document:
keep_tex: true
---