4

Text in the code section of a Tufte formatted, Rmarkdown document does not seem to wrap. I have tried several options and suggestions, but nothing works. I am guessing that all of the other suggestions I could find on StackOverflow did not work, because of the "tufte" format. I am using knitr to construct HTML or PDF documents. Here is the minimal example:

    ---
    title: "Width Minimal Example"
    output:
      tufte::tufte_handout: default
      tufte::tufte_html: default
    ---

    ```{r setup, include=FALSE}
    library(tufte)
    library(formatR)
    # invalidate cache when the tufte version changes
    knitr::opts_chunk$set(tidy = TRUE, cache.extra = packageVersion('tufte'))
    options(htmltools.dir.version = FALSE)
    ```

    ```{r, tidy='styler', tidy.opts=list(width.cutoff=50)}
    filename <- "/Test/test/test/test/test/test/test/test/test/test/test/test.data"
    ```

When I use knitr to produce HTML or PDF (handout), the "filename" variable runs out of the textbox allotted for code. I've looked through the "tufte.css" file and nothing there seems to describe the width of text in code boxes.

Ideally, the text in the code box would not only wrap, but indent a bit so that the person reading the code would easily be able to see which lines were new lines and which lines were wrapped lines. Thanks!

Mark Bower
  • 569
  • 2
  • 16
  • 1
    Maybe you could use the `here()` function from the [here package](https://here.r-lib.org/) as a workaround? E.g. `filename <- here("test.data")` (per [github.com/jennybc/here_here](https://github.com/jennybc/here_here) ) – jared_mamrot Jun 30 '20 at 11:25
  • 1
    Thank you for the link, jared_mamrot. I had not seen that package, previously. It certainly is useful. I was hoping for a more general way of wrapping all text in the Tufte format. Other examples I could add to my original post would be when a function call has too many parameters and becomes too wide or when R returns too many characters (e.g., this often happens with vectors and matrices). – Mark Bower Jul 02 '20 at 18:25
  • No problem; I see exactly what you're trying to do - I wrap all my text in my RMarkdown docs (both code and output) - but I wasn't able to figure out a solution that works with Tufte formatting. Hopefully someone else with more domain-specific knowledge can help ([Xie Yihue](https://stackoverflow.com/users/559676/yihui-xie)?) – jared_mamrot Jul 03 '20 at 06:06

0 Answers0