2012-07-03 48 views
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檢查知道這個文件?

回答

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命名)文件名,給它一個別名,如上例,你應該沒問題。

+0

嗨羅馬,謝謝你的提示。我將.Rd文件的文件名更改爲subset.Rd,並將\ name和\ alias更改爲\ name {subset-method} \ alias {[,stack,ANY,ANY-method}。這解決了這個問題。謝謝! – Marco