yihui / knitr-examples

A collection of knitr examples
488 stars 586 forks source link

Quarto PDF #87

Closed jkylearmstrong closed 1 year ago

jkylearmstrong commented 1 year ago

Attempting to use https://github.com/yihui/knitr-examples/blob/master/077-wrap-output.Rmd

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 = xfun::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 = '\n')
    }
  hook_output(x, options)
  }
  )

to solve wrapping text output in a Quarto PDF output, however, it produces an error:

Error in hook_output(x, options) : could not find function "hook_output"
Calls: .main ... <Anonymous> -> lapply -> FUN -> <Anonymous> -> <Anonymous>
Execution halted
yihui commented 1 year ago

If this only occurs in Quarto, please report to Quarto instead: https://github.com/quarto-dev/quarto-cli/issues Thanks!

jkylearmstrong commented 1 year ago

Thanks!