How to wrap a very long output of point R in R knitr

I am trying to add a long paragraph to a pdf file using R Sweave / Knitr. This long paragraph is extracted from one of the excel columns and glued together. You can view the paragraph as a 1 on 1 object:

cat("loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong")

Currently, if I am executing this long paragraph in pdf format:

 \documentclass{article}
 \begin{document}

 <<warning=FALSE, comment=NA, message=FALSE, echo=FALSE, tidy=TRUE,background="white">>=

 cat("looonno, oooooooooooooooooooooo, ooooooooooooooooooooooo, ooooooooooooooooooo, ooooonnnnnnnnnnnnnnnnnng")

 @

 \end{document}

the output cannot wrap the text itself, and the result will always be like this: enter image description here

Exit goes beyond the page.

I tried to use it option(width=60), but in this situation this will not help if there are not several elements in one object.

Hopefully some can come up with an idea that will make the text wrap around the field.

+4
source share
1 answer

strwrap, writeLines width :

:

enter image description here

\documentclass{article}
\begin{document}

<<warning=FALSE, comment=NA, message=FALSE, echo=FALSE, tidy=TRUE,background="white">>=



x=paste0("looonno, oooooooooooooooooooooo, ooooooooooooooooooooooo, ooooooooooooooooooo, ooooonnnnnnnnnnnnnnnnnng, texttttttttttttttttttttttttt,
        goessssssssssssssss,onnnnnnnnnnn, foreverrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr, annnnnnnnnnnnnnnnnnnnnnnnnnd, everrrrrrrr")

cat("Before:","\n")

cat(x,"\n")

cat("After:","\n")

cat(writeLines(strwrap(x, width = 100)))


@

\end{document}
+2

Source: https://habr.com/ru/post/1680395/


All Articles