Note: please ignore this example if the version of your formatR package is greater than 1.3.2, because line breaks will be automatically preserved.

This demos shows you how to replace \n to a real line break in the source.

This is what you normally see in the output:

x = 'this is a long long
string with several
lines'

Modify the source hook:

library(knitr)
knit_hooks$set(source = function(x, options) {
  paste0('\n\n```r\n', gsub('\\n', '\n', x, fixed=TRUE), '\n```\n\n')
})

Now we test the source hook:




Try the parsermd package in your browser

Any scripts or data that you put into this service are public.

parsermd documentation built on May 20, 2021, 5:08 p.m.