I'm experimenting with the minimal bookdown book and am attempting to successfully wrap long R code when using the Build bookdown::pdf_book option.
I attempted the following which I found as a potential solution, but with no success.
library(knitr)
hook_output = knit_hooks$get('output')
knit_hooks$set(output = function(x, options) {
# this hook is used only when the linewidth option is not NULL
if (!is.null(n <- options$linewidth)) {
x = knitr:::split_lines(x)
# any lines wider than n should be wrapped
if (any(nchar(x) > n)) x = strwrap(x, width = n)
x = paste(x, collapse = '
')
}
hook_output(x, options)
})
'''
question from:
https://stackoverflow.com/questions/65838860/wrapping-long-r-code-using-bookdown-build 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…