Documenting equations with deqn and roxygen

偶尔善良 提交于 2019-12-04 08:59:07

问题


I'm using \deqn{}{} with roxygen2 to document equations for a function in a package. The LaTeX (the 1st argument to deqn) renders fine because white space is ignored in LaTeX equations, but I have a problem with the ASCII (the 2nd argument to deqn) representation.

The problem is that my formatting is destroyed (it appears roxygen puts the entire deqn command on a "single line" and then wraps that line at ~60 columns or so). Is there a way to force roxygen2 to preserve the white space formatting in my roxygen commands/comments in the .R file?

I have the following code in a file, example.R:

#'Example
#'
#'deqn ASCII example
#'
#'\deqn{ \sigma = \sqrt{ \frac{Z}{n} \sum
#'  \left[ \textstyle\frac{1}{2}\displaystyle
#'    \left( \log \frac{H_i}{L_i} \right)^2  - (2\log 2-1)
#'    \left( \log \frac{C_i}{O_i} \right)^2 \right] }
#'}{sqrt(N/n * runSum(0.5 * log(OHLC[,2]/OHLC[,3])^2 -
#'           (2*log(2)-1) * log(OHLC[,4]/OHLC[,1])^2, n))}
#'
#'@param x An example parameter
#'@return A example result
#'@author Joshua Ulrich
#'@keywords ts
#'@export
"example" <-
function(x) {
}

And I use the following R code to generate the example.Rd file:

library(roxygen2)
setwd("dir/containing/example.R/")
dir.create("man",FALSE)
roclet <- rd_roclet()
roc_proc(roclet, "example.R", ".")
roc_out(roclet, "example.R", ".")

You can generate the text representation of the example.Rd file using this command at the command line:

R CMD Rd2txt dir/containing/example.R/man/example.Rd

The Details section of the output from the above command looks like:

sqrt(N/n *
  runSum(0.5 * log(OHLC[,2]/OHLC[,3])^2 - (2*log(2)-1) *
  log(OHLC[,4]/OHLC[,1])^2, n))

whereas I would like it to look like:

sqrt(N/n * runSum(0.5 * log(OHLC[,2]/OHLC[,3])^2 -
         (2*log(2)-1) * log(OHLC[,4]/OHLC[,1])^2, n))

回答1:


According to Hadley Wickham, line wrapping will be removed in future versions of roxygen. So the solution for roxygen2 is to roxygenize the file (or package), then manually update the text equation in the affected .Rd file(s).



来源:https://stackoverflow.com/questions/14041601/documenting-equations-with-deqn-and-roxygen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!