4

我在 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 检查知道这个文件吗?

4

1 回答 1

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 命名的)文件名,给它一个别名,就像上面的例子一样,你应该没问题。

于 2012-07-03T08:47:14.233 回答