您看到的是函数文档字符串。强烈建议您也为您的函数编写这些。
它看起来像这样(参见源代码):
library(docstring)
mypaste <- function(x, y = "!"){
#' Paste two items
#'
#' @description This function pastes two items
#' together.
#'
#' By using the description tag you'll notice that I
#' can have multiple paragraphs in the description section
#'
#' @param x character. The first item to paste
#' @param y character. The second item to paste Defaults to "!" but
#' "?" would be pretty great too
#' @usage mypaste(x, y)
#' @return The inputs pasted together as a character string.
#' @details The inputs can be anything that can be input into
#' the paste function.
#' @note And here is a note. Isn't it nice?
#' @section I Must Warn You:
#' The reference provided is a good read.
#' \subsection{Other warning}{
#' It is completely irrelevant to this function though.
#' }
#'
#' @references Tufte, E. R. (2001). The visual display of
#' quantitative information. Cheshire, Conn: Graphics Press.
#' @examples
#' mypaste(1, 3)
#' mypaste("hey", "you")
#' mypaste("single param")
#' @export
#' @importFrom base paste
return(paste(x, y))
}
当你检查它时:
?mypaste
Paste two items
Description:
This function pastes two items together.
By using the description tag you'll notice that I can have
multiple paragraphs in the description section
Usage:
mypaste(x, y)
Arguments:
x: character. The first item to paste
y: character. The second item to paste Defaults to "!" but "?" would be pretty great too
Details:
The inputs can be anything that can be input into the paste
function.
Value:
The inputs pasted together as a character string.
I Must Warn You:
The reference provided is a good read.
Other warning:
It is completely irrelevant to this function though.
Note:
And here is a note. Isn't it nice?
References:
Tufte, E. R. (2001). The visual display of quantitative
information. Cheshire, Conn: Graphics Press.
Examples:
mypaste(1, 3)
mypaste("hey", "you")
mypaste("single param")
有关文档字符串的更多详细信息R:
但请记住不要过度使用您的文档。这里有一些好的代码文档的好资源: