Question

I have two functions in the same family. I am documenting with roxygen2 and can put them together in the same help file but do not know how to make the usage field in the documentation have both functions.

I tried:

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

This gives:

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

I tried comma separated and it gives just the first and I tried separate usage tags and it uses just the first one.

How can I make two items in the usage field with roxygen and so they'll be on separate lines (eg ?lapply)?

EDIT: Per GeeSee's question, the whole .R file

#' 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
Was it helpful?

Solution

I think you want to use @rdname and abandon the idea of using @usage

So, pick a name and use it for all of them. e.g. add this to all your roxygen blocks

#' @rdname matrix2vectors

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top