R 方括号“[`函数的文档
我在R中有一个函数,看起来有点像这样:R 方括号“[`函数的文档,r,function,documentation,square-bracket,rd,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
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 check知道这个文件吗?如果您查看
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命名的)文件名,给它一个别名,如上面的示例所示,您应该可以。Hi Roman,谢谢您的提示。我将.Rd文件名更改为subset.Rd,并将\name和\alias更改为\name{subset method}\alias{[,stack,ANY ANY method}.这解决了问题。谢谢!