用deqn和roxygen记录方程式 [英] Documenting equations with deqn and roxygen

查看:174
本文介绍了用deqn和roxygen记录方程式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将\deqn{}{}与roxygen2一起使用,以记录软件包中函数的方程式. LaTeX(deqn的第一个参数)呈现出很好的效果,因为在LaTeX方程中忽略了空格,但是ASCII(deqn的第二个参数)表示存在问题.

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.

问题是我的格式被破坏(roxygen似乎将整个deqn命令放在单行"上,然后将该行换成〜60列左右).有没有办法强迫roxygen2在.R文件的roxygen命令/注释中保留空白格式?

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?

我在文件example.R中具有以下代码:

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) {
}

然后我使用以下R代码生成example.Rd文件:

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", ".")

您可以在命令行上使用以下命令生成example.Rd文件的文本表示形式:

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

上面命令输出的 Details 部分如下所示:

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))

推荐答案

根据Hadley Wickham ,将自动换行在未来版本的roxygen中删除.因此,roxygen2的解决方案是对文件(或程序包)进行重新充电,然后手动更新受影响的.Rd文件中的文本方程式.

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).

这篇关于用deqn和roxygen记录方程式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆