2012-11-29 36 views
4

我在同一系列中有两个功能。我正在使用roxygen2进行文档编制,并且可以将它们放在同一个帮助文件中,但不知道如何使文档中的使用字段具有这两种功能。在roxygen2中提供两种用法

我想:

#' @usage matrix2vectors(cor.mat) vectors2matrix(cor.vect) 

这给:

matrix2vectors(cor.mat) vectors2matrix(cor.vect) 

我试图用逗号隔开,并只给出第一,我想单独使用标签和它使用的只是第一个。

如何使用roxygen在使用领域中制作两个项目,因此它们将位于不同的线条上(例如?lapply)?

编辑:每GeeSee的问题,整个.R文件

#' Convert Between Correlation Matrix and Upper Triangle Dataframe 
#' 
#' Tools to convert between a correlation matrix and a dataframe of upper triangle 
#' values and variable components. The dataframe is more intuitive for applying 
#' functions while the correlation matrix is more intuitive to visualize. 
#' 
#' @aliases matrix2vectors, vectors2matrix 
#' @usage matrix2vectors(cor.mat) 
#' @usage vectors2matrix(cor.vect) 
#' @rdname matrix2vectors 
#' @param cor.mat A square, symetrical matrix with a diagonas of 1s (a correlation matrix). 
#' @param cor.vect A dataframe with the row variables of the correlation matrix in the first 
#' column, the column names in the second column and the corresponding correlations in the 
#' third column. 
#' @export 
#' @examples 
#' (mat <- round(cor(mtcars[, 1:5]), 2)) 
#' matrix2vectors(mat) 
#' cor.vect <- matrix2vectors(round(cor(mtcars[, 1:5]), 2)) 
#' vectors2matrix(cor.vect) 
matrix2vectors <- function(cor.mat) { 
    nmscor <- colnames(cor.mat) 
    rows <- nmscor[1:(length(nmscor)-1)] 
    cols <- nmscor[2:length(nmscor)] 
    rowdim <- 1:length(rows) 
    row.var <- rows[unlist(lapply(seq_along(rowdim), function(i) rowdim[1:i]))] 
    col.var <- rep(cols, 1:length(cols)) 
    cors <- cor.mat[upper.tri(cor.mat)] 
    data.frame(row.var, col.var, cors) 
} 
#' @export 

#' @export 
vectors2matrix <- function(cor.vect) { 
    dimnms <- unique(c(as.character(cor.vect[, 1]), 
     as.character(cor.vect[, 2]))) 
    mat <- matrix(NA, length(dimnms), length(dimnms)) 
    mat[upper.tri(mat)] <- cor.vect[, 3] 
    diag(mat) <- 1 
    dimnames(mat) <- list(dimnms, dimnms) 
    mat[lower.tri(mat)] <- t(mat)[lower.tri(mat)] 
    mat 
} 
#' @export 
+0

为什么使用'@ usage'标记? – GSee

+0

看看[这个R文件](https://r-forge.r-project.org/scm/viewvc.php/pkg/R/TFX.R?view=markup&revision=16&root=truefx)创建[这个Rd文件](https://r-forge.r-project.org/scm/viewvc.php/pkg/man/QueryTrueFX.Rd?view=markup&revision=14&root=truefx)与多个用途 – GSee

回答

5

我想你想使用@rdname,并放弃使用@usage

这样的想法,选择一个名字,并用它为他们所有。例如将此添加到您的所有roxygen区块

#' @rdname matrix2vectors

+2

@TylerRinker - 您可以检查从这个文件(从你自己的回购站)中找到一个rdname的例子:https://github.com/trinker/pacman/blob/master/R/p_functions.R – Dason

+1

在我的辩护中,我确实有一些帮助设置该存储库;-) –

+0

@TylerRinker从机器人的帮助算作真正的帮助? – Dason

相关问题