reprex icon indicating copy to clipboard operation
reprex copied to clipboard

Should reprex output add new lines with long (wide) error & warning messages?

Open EconomiCurtis opened this issue 4 years ago • 1 comments

When a reprex output shows a long warning or error message, it does not add new lines consistent with typical experience with character max-widths from the R console.

For example, (perhaps an odd example, but it's one I recently used on RStudio Community)

library(dplyr)
df <- tibble(
  y = LETTERS[1:3],
  x1 = 1:3,
  x2 = 3:5
)
lm(y ~ x1 + x2, data = df)

this produces a somewhat long error,

#> Warning in storage.mode(v) <- "double": NAs introduced by coercion
#> Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...): NA/NaN/Inf in 'y'

In the console, this appears as the following, Screenshot R Console: image

On Stack Overflow, this appears as the following (not you have to scroll left to see the full error) Screenshot Stack Overflow: image

Screenshot RStudio Community: image

That horizontal scrolling can be awkward for some folks. Particularly for long errors and warnings (e.g. some package install errors). I feel it'd be ideal for warning and error messages to roughly replicate the new lines seen in the R console.

New lines can certainly be added manually -- I have a feeling there are other concerns or trickiness I'm missing -- but I feel the default behavior should be with styling that works better on gh, so, and rstudio community.

EconomiCurtis avatar Mar 26 '22 21:03 EconomiCurtis

Links from a bit of searching on this:

https://github.com/yihui/knitr/issues/1142 has advice on "customize the error/warning hook function to wrap the error/warning message"

A hack Hadley has used in book-y projects to wrap errors and warnings: https://github.com/hadley/adv-r/blob/dc49c3872c3530ac08716fd4f4c235b01266a4ce/common.R#L44-L64

@cderv Do you have any quick input? As in, is there some simple knitr option I could use to wrap errors and warnings? I suspect not.

jennybc avatar Aug 14 '22 16:08 jennybc