记录功能关闭 [英] Documenting function closures

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

问题描述

假设我的包中有一个函数闭包,例如

Suppose I have a function closure in my package, for example

f = function(x) {
    x = x
    g = function(y) x <<- y
    h = function() x
    list(g = g, h = h)
}

l = f(5)
l$g(10)
l$h()

记录此功能的正确方法是正确的(在官方 CRAN 意义上) ?

What is the correct (in the official CRAN sense) way of documenting this function? In particular,


  1. 我想使用 roxygen2

  2. 我想为函数 g h
  3. $ b $提供文档b
  1. I would like to use roxygen2
  2. I would like to provide documentation for the functions g and h


推荐答案

一种方法是做与?family 类似的事情在 Value g() h()的位置 .Rd 文件的c>部分。然后在定制的 \部分中提供有关 g() h()的扩展文档{foo} ,您将在这两个函数的 Value 部分条目中指向它们。

One way would be to do something similar to ?family where you document g() and h() in the Value section of the .Rd file. Then provide extended documentation about g() and h() in a bespoke \section{foo}, which you point to in the Value section entries for the two functions.

\value{
  Returns an object of class \code{"foo"}, a list with the
  following components:

  \item{g}{function; does foo. See Returned Functions for details.}
  \item{h}{function; does bar. See Returned Functions for details.}
}
\section{Returned Functions}{
  The returned functions do, blah blah...

  \code{g} is defined as

  \preformatted{
  g(x, y, z, ...)
  }

  Arguments are:

  \describe{
    \item{x}{foo}
    \item{y}{foo}
    \item{z}{foo}
  }
}

虽然氧气无法从参数 @param ,但是您应该可以将其写为任意的roxygen部分,以添加到Rd文件中。 Value 部分可以写为标准的roxygen标记,只需按需输入定制部分。

Whilst roxygen won't be able to do this from the argument @param, but you should be able to write this as an arbitrary roxygen section to add to the Rd file. The Value section can be written as standard roxygen markup, only the bespoke section would need to be entered literally.

这篇关于记录功能关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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