简体   繁体   中英

How to get roxygen2 to interpret backticks as code formatting?

The standard way of writing documentation with code formatting is by using \code{} .

That is, #' @param foo value passed on to \code{bar()} becomes

Arguments

foo value passed on to bar()

However, I've seen some packages (ie dplyr ) using backticks instead of \code{} to the same effect. This is much better, since it's less clunky and allows for very nice syntax highlighting.

However, if I try that on my own package, the backticks get interpreted as... just backticks, like any other character.

The documentation for dplyr::across() , for example, starts with:

#' @description
#' `across()` makes it easy to apply the same transformation to multiple [...]

which gets compiled and displayed in the man page as:

Description

across() makes it easy to apply the same transformation to multiple [...]

But if I try something similar on my package, I get:

Description

`across()` makes it easy to apply the same transformation to multiple [...]

Weirdly, I've forked the package glue (which also manages to use backticks for code formatting) for a simple PR, and if I build the package locally, the backticks work (I get code formatting). Can't for the life of me figure out why it works there but not for my package.


So, is there some setting I need to modify to get this to work? I checked the dplyr.Rproj but found nothing relevant. I also glanced at the Doxyfile , but didn't know what it did or what I'd even be looking for there.

All credit goes to @rawr's comment to the question, just formalizing it with an answer:

The secret is in the roxygen2 documentation : just add the following to the end of the package DESCRIPTION file:

# DESCRIPTION file
# [... rest of file ...]
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2  # actually works since 6.0.0

As that code would imply, this sets roxygen2 to interpret the commands as good ol' Markdown like we're used to using here on SO and elsewhere. This also implies all the other standard Markdown commands such as **bold** and *italics* , as well as [text](http://www.url.com) , code blocks defined by ``` , itemized and enumerated lists, etc. It's a huge improvement across the board.

Though be careful and take a look at the documentation, since there are a few gotchas. For instance, an empty line isn't necessary to start lists, so don't start any lines with #' 1. [...] or #' * [...] or you'll accidentally create a list.), There's also a few things which don't work yet. but they're pretty minor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM