用roxygen记录setter函数 [英] Documenting setter functions with roxygen

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

问题描述

我有一个功能,它不需要任何R对象独特的 attr 的广告。基本演示:

 #'Setter function 
#'@param x a R object
#'@ param value一个字符值设置
#'@export
`foo< -`< - function(x,value){
attr(x,'foo')<
return(x)
}

除了生成一个很好的Rd文件,相关部分:

  \usage {
foo(var,value)<
}

当然,它会在运行 R时触发警告CMD检查,因为它应该是 foo(var)< - value



任何提示都会非常感谢!






更新:感谢 richierocks 似乎有一个修复

解决方案

您可以使用roxygen标签 @usage



这是我的一个包中的一个例子:

 #'@rdname pattern 
#'@usage pattern(x)< - value
#'@param value新值
#'@export pattern < -
pattern < - < - function(x,value = c(^,($ |(_\\d +(_ \\\ \\ d +)*)$))){
attr(x,pattern)< - value
x
}
p $ p>




这将产生所需的文档:

 用法

pattern(x)< - value

参数
x monitoredydata对象

值新值


I have a function that does nothing more than ads a unique attr to any R object. Base demo:

#' Setter function
#' @param x an R object
#' @param value a character value to set
#' @export
`foo<-` <- function(x, value){
    attr(x, 'foo') <- value
    return(x)
}

This works like a charm except for generating a good Rd file, relevant part:

\usage{
  foo(var, value) <- value
}

And of course it triggers a warning while running R CMD check as it should be foo(var) <- value.

Any hints would be really apprecieted!


Update: thanks to richierocks it seems there is a fix

解决方案

You can use the roxygen tag @usage

Here is an example from one of my packages:

#' @rdname pattern
#' @usage pattern(x) <- value
#' @param value New value
#' @export pattern<-
"pattern<-" <- function(x, value=c("^", "($|(_\\d+(_\\d+)*)$)")){
  attr(x, "pattern") <- value
  x
}


This results in my desired documentation:

Usage

  pattern(x) <- value

Arguments
x surveydata object

value New value

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

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