Open bastienchassagnol-servier opened 2 years ago
Hi @bastienchassagnol-servier would you have an example for how this might work? Right now code should be delimited by backticks, not using the \code{}, but happy for making it look better. It would need to work for both html and pdf outputs.
Hi @dicook, I carried out some experiences to check the behaviour of downlit library. With the current rjtools template, you simply need to load library downlit in the setup chunk, to automatically highlight chunks of R code.
However, for inline code formatting, you need to explicitly call either function downlit::autolink("R_function") to highlith a R function, or href_topic or href_package to automatically generate a web link towards the corresponding vignette or CRAN reference webpage.
Here's the code used for that purpose, using the same YAML preamble as provided by rjtools package:
library(ggplot2)
ggplot(mtcars, aes(hp, mpg)) + geom_point() + geom_smooth()
The r downlit::autolink("stats::median()")
is a function highlited using the r downlit::href_package("downlit")
package // r downlit::autolink("library(downlit)")
package // downlit
package. It's also possible to automatically link to a specific topic:
r downlit::autolink('vignette("mclust", package = "mclust")')
or r href_topic("mclust", "mclust")
.`
And the corresponding HTML output:
(you can notice that additionaly to the formatting of inline piece of code, by dragging the mouse over it, an automatic link to the corresponding documention has been generated). Unfortunately, this doesn't work as well with the PDF output:
To sum it up, downlit is a relevant tool to highlight pieces of code, but lacks in my opinion, two key features:
Maybe, you may develop a similar device as command \CRANpkg, but that would enable to highlight additionally inline and multiline R functions and blocks + enable automated redirection to the specific vignette of a package.
In RJwrapper.tex is provided a \code{R_function} command, that enabled in previous purely Latex styles to emphasize specific R functions. However, it seems that this option has not been adjusted to the new Rmd format, as it's only working for the Latex ouput (the text within code brackets does not even appear in the HTML version).
It seems that enabling the downlit personalization, as suggested by the distill documentation, would be a rather nice evolution to highlight these tiny pieces of code, wouldn't it?