Pre or post-processor fragments

Is there some mechanism with which I can convert the comments that roxygen sees, preferably before it converts roxygen-> rd?

For example, suppose I have:

#' My function. Does stuff with numbers. #' #' This takes an input `x` and does something with it. #' @param xa number. myFunction <- function (x) { } 

Now suppose I want to do some conversion of the comment before roxygen analyzes it, for example, replacing all instances of things in backticks with \code{} . I.e:

 preprocess <- function (txt) { gsub('`([^ ]+)`', '\\\\code{\\1}', txt) } # cat(preprocess('Takes an input `x` and does something with it'.)) # Takes an input \code{x} and does something with it. 

Is there any way to pass preprocess to roxygen so that it runs it on docs earlier (or after that would work in this case) does roxygen do its document creation?

I do not want to do a constant find-replace in my .r files. As you can guess from my example, I am aiming for some rudimentary markup support in my roxygen comments and, therefore, want to save the .r files as-to in order to maintain readability (and programmatically insert \code{..} ).

Should I just write my own version of roxygenise , which launches a preprocess for all detected roxygen-style comments in my files, temporarily saves them somewhere, and then runs the actual roxygenise on them?

+68
r roxygen2
Mar 21 '13 at 5:42 on
source share
1 answer

After repeating this after a couple of years, it looks like Roxygen has a register.preref.parsers function that you can use to embed your own parsers in roxygen. One such application is the promising maxygen package (markdown + roxygen = maxygen), which is a very neat implementation of markdown processing for roxygen comments (although only for the CommonMark specification), and you can see how the macument function is used in this package. I look forward to "pandoc + roxygen = pandoxygen" ... :)

0
Sep 23 '15 at 0:16
source share



All Articles