Kev*_*hey 4 r roxygen roxygen2
作为一个简单,具体的例子:
#' Inverse Value Matching
#'
#' Complement of \code{%in%}. Returns the elements of \code{x} that are
#' not in \code{y}.
#' @usage x %nin% y
#' @param x a vector
#' @param y a vector
#' @export
"%nin%" <- function(x, y) {
return( !(x %in% y) )
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试构建一个包时,该函数似乎被忽略,并且没有生成文档.
在http://cran.r-project.org/doc/manuals/r-release/R-exts.html#Documenting-functions上似乎有关于二进制中缀函数的单行模糊,但我很难时间解析它,以及它对Roxygen文档意味着什么.
您需要%
在使用部分中转义s.另外,我认为您可能需要指定一个rdname
#' Inverse Value Matching
#'
#' Complement of \code{%in%}. Returns the elements of \code{x} that are
#' not in \code{y}.
#' @usage x \%nin\% y
#' @param x a vector
#' @param y a vector
#' @export
#' @rdname nin
"%nin%" <- function(x, y) {
return( !(x %in% y) )
}
Run Code Online (Sandbox Code Playgroud)
这是我在个人包装中的功能.我不认为我曾经实际使用过该函数,但roxygenize
确实创建了一个帮助文件并且包通过了R CMD check
.
#' percent in
#'
#' calculate the percentage of elements of \code{table} that are in \code{x}
#'
#' @param x vector or NULL: the values to be matched
#' @param table vector or NULL: the values to be matched against
#' @return percentage of elements of \code{x} that are in \code{table}
#' @author gsee
#' @usage x \%pctin\% table
#' @examples
#' letters[1:10] %pctin% letters[1:3] # 30% of the second arg ar in the first
#' @export
#' @rdname PctIn
"%pctin%" <- function(x, table) length(x[x %in% table])/length(x)
Run Code Online (Sandbox Code Playgroud)