rmarkdown text out of margin in pdf documnet

Hello, I have the problem with the output text in the pdf document going out of margin when the document is rendered using rmarkdown::render with output_format = 'pdf_document'. This can be avoided by using knit button in RStudio but sometimes I need the documents being generated by running scripts. Here is a reproducible example:

---
title: "Test"
output: pdf_document
geometry: margin=2cm
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, tidy.opts = list(width.cutoff = 40), tidy = TRUE)
```

```{r}
print(rep("ABCDEFGH", 20))
```

I'm using
rmarkdown_2.28
pdfTeX 3.14159265-2.6-1.40.21 (TeX Live 2020)
kpathsea version 6.3.2
R version 4.4.0

Thank you for any suggestions.