我在同一个家庭中有两个功能。我正在使用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 :(得分:5)
我认为你想使用@rdname
并放弃使用@usage
因此,选择一个名称并将其用于所有这些名称。例如将此添加到所有的氧气块
#' @rdname matrix2vectors