平方括号`[`函数的文档

时间:2012-07-03 08:09:31

标签: r function documentation square-bracket rd

我在R中有一个看起来像这样的函数:

setMethod('[', signature(x="stack"),definition=function(x,i,j,drop){
  new('class', as(x, "SpatialPointsDataFrame")[i,]) })

我用它来从堆叠对象中获取单个元素。对于我正在构建的包,我需要一个.Rd文件来记录该函数。我把它存储为[.Rd但不知何故R CMD检查没有看到这个。它返回:

Undocumented S4 methods:  generic '[' and siglist 'MoveStack,ANY,ANY'

[.Rd文件以这些行开头:

\name{[}    
\alias{[}
\alias{[,stack,ANY,ANY-method}    
\docType{methods}    
\title{Returns an object from a stack}    
\description{Returning a single object}    
\usage{
  \S4method{\[}{stack,ANY,ANY}(x,i,y,drop)
}

知道如何让R CMD检查这个文件吗?

1 个答案:

答案 0 :(得分:3)

如果您查看sp包的源代码,例如SpatialPolygons-class.Rd,请参阅“方法”部分:

\section{Methods}{
Methods defined with class "SpatialPolygons" in the signature:
  \describe{
    \item{[}{\code{signature(obj = "SpatialPolygons")}: select subset of (sets of) polygons; NAs are not permitted in the row index}
    \item{plot}{\code{signature(x = "SpatialPolygons", y = "missing")}: 
    plot polygons in SpatialPolygons object}
    \item{summary}{\code{signature(object = "SpatialPolygons")}: summarize object}
    \item{rbind}{\code{signature(object = "SpatialPolygons")}: rbind-like method}
  }
}
定义了[

方法。

文件的名称和类是

\name{SpatialPolygons-class}
\alias{[,SpatialPolygons-method}

如果您查看?SpatialPolygons的帮助页面,您应该看到

> Methods
> 
> Methods defined with class "SpatialPolygons" in the signature:
> 
> [ signature(obj = "SpatialPolygons"): select subset of (sets of)
> polygons; NAs are not permitted in the row index
> 

所以我猜想如果你指定一个正确的(ASCII命名的)文件名,给它一个别名,如上例所示,你应该没问题。