Skip to content

Commit

Permalink
guard against renderMarkdown(text = character(0) or '') (yihui/knitr#918
Browse files Browse the repository at this point in the history
)
  • Loading branch information
yihui committed Dec 18, 2014
1 parent d2ca2ff commit 24a71d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions R/renderMarkdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ rendererOutputType <- function(name) {
#' @export renderMarkdown
#' @examples
#' (renderMarkdown(text = "Hello World!"))
#' # a few corner cases
#' (renderMarkdown(text = character(0)))
#' (renderMarkdown(text = ''))
renderMarkdown <- function(
file, output = NULL, text = NULL, renderer = 'HTML', renderer.options = NULL,
extensions = getOption('markdown.extensions'), encoding = getOption('encoding')
Expand Down Expand Up @@ -125,6 +128,11 @@ renderMarkdown <- function(
stop('HTML options must be a character vector')
}

if (length(text) == 0 || text == '') {
if (is.null(output)) return(invisible(character(length(text))))
file.create(output)
return()
}
ret <- .Call(rmd_render_markdown,
file, output, text, renderer, renderer.options, extensions)

Expand Down
3 changes: 3 additions & 0 deletions man/renderMarkdown.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ GitHub. C stubs are available to implement new renderers.
}
\examples{
(renderMarkdown(text = "Hello World!"))
# a few corner cases
(renderMarkdown(text = character(0)))
(renderMarkdown(text = ""))
}
\seealso{
\code{\link{markdownExtensions}}, \code{\link{markdownHTMLOptions}},
Expand Down

0 comments on commit 24a71d0

Please sign in to comment.