我在同一系列中有兩個功能。我正在使用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
爲什麼使用'@ usage'標記? – GSee
看看[這個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