Skip to content

Commit 919e7ef

Browse files
committed
Added examples to docstring
1 parent ac6dcb2 commit 919e7ef

2 files changed

Lines changed: 110 additions & 1 deletion

File tree

R/docstring.R

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,61 @@ has_docstring <- function(fun, fun_name = as.character(substitute(fun))){
8787
#' @importFrom utils package.skeleton
8888
#' @importFrom utils browseURL
8989
#' @aliases ?
90-
#'
90+
#'
91+
#' @examples
92+
#' \dontrun{
93+
#' square <- function(x){
94+
#' #' Square a number
95+
#' #'
96+
#' #' Calculates the square of the input
97+
#' #'
98+
#' #' @param x the input to be squared
99+
#'
100+
#' return(x^2)
101+
#' }
102+
#'
103+
#' docstring(square)
104+
#' ?square
105+
#'
106+
#'
107+
#' mypaste <- function(x, y = "!"){
108+
#' #' Paste two items
109+
#' #'
110+
#' #' @description This function pastes two items
111+
#' #' together.
112+
#' #'
113+
#' #' By using the description tag you'll notice that I
114+
#' #' can have multiple paragraphs in the description section
115+
#' #'
116+
#' #' @param x character. The first item to paste
117+
#' #' @param y character. The second item to paste Defaults to "!" but
118+
#' #' "?" would be pretty great too
119+
#' #' @usage mypaste(x, y)
120+
#' #' @return The inputs pasted together as a character string.
121+
#' #' @details The inputs can be anything that can be input into
122+
#' #' the paste function.
123+
#' #' @note And here is a note. Isn't it nice?
124+
#' #' @section I Must Warn You:
125+
#' #' The reference provided is a good read.
126+
#' #' \subsection{Other warning}{
127+
#' #' It is completely irrelevant to this function though.
128+
#' #' }
129+
#' #'
130+
#' #' @references Tufte, E. R. (2001). The visual display of
131+
#' #' quantitative information. Cheshire, Conn: Graphics Press.
132+
#' #' @examples
133+
#' #' mypaste(1, 3)
134+
#' #' mypaste("hey", "you")
135+
#' #' mypaste("single param")
136+
#' #' @export
137+
#' #' @importFrom base paste
138+
#'
139+
#' return(paste(x, y))
140+
#' }
141+
#'
142+
#' ?mypaste
143+
#' }
144+
#'
91145
#' @export
92146
docstring <- function(fun, fun_name = as.character(substitute(fun)),
93147
rstudio_pane = getOption("docstring_rstudio_help_pane"),

man/docstring.Rd

Lines changed: 55 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)