Skip to content

Commit

Permalink
Plan B: put reprex_info() at top of body
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed Oct 12, 2017
1 parent 25ca243 commit e3ccba7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions R/reprex-info.R
Expand Up @@ -5,6 +5,7 @@
#'
#' @examples
#' reprex_info()
reprex_info <- function(prefix = "#'") {
paste(prefix, "Created by the reprex package;", Sys.Date())
reprex_info <- function() {
message(paste("Created by the reprex package;", Sys.Date()))
invisible()
}
4 changes: 3 additions & 1 deletion R/reprex.R
Expand Up @@ -253,6 +253,9 @@ reprex <- function(x = NULL,
message("Install the styler package in order to use `styler = TRUE`.")
}
}
if (advertise) {
the_source <- c("reprex::reprex_info()", "", the_source)
}

outfile_given <- !is.null(outfile)
if (outfile_given && is.na(outfile)) {
Expand Down Expand Up @@ -281,7 +284,6 @@ reprex <- function(x = NULL,
the_source <- apply_template(c(
fodder[[venue]],
si = isTRUE(si),
advertisement = if (advertise) reprex_info() else NULL,
devtools = requireNamespace("devtools", quietly = TRUE),
comment = comment,
user_opts_chunk = opts_chunk,
Expand Down
2 changes: 0 additions & 2 deletions inst/templates/REPREX.R
Expand Up @@ -9,8 +9,6 @@ knitr::opts_knit$set(upload.fun = knitr::imgur_upload)
{{{user_opts_chunk}}}
{{{user_opts_knit}}}

{{advertisement}}

#+ reprex-body
{{{body}}}

Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-styler.R
Expand Up @@ -5,6 +5,7 @@ test_that("ugly code gets restyled", {
ret <- reprex(
input = c("a<-function( x){", "1+1} "),
styler = TRUE,
advertise = FALSE,
render = FALSE
)
i <- which(ret == "#+ reprex-body")
Expand All @@ -21,7 +22,7 @@ test_that("bang bang bang is styled correctly", {
'nameshift <- c(SL = "Sepal.Length")',
"head(dplyr::rename(iris[, 1:2], !!! nameshift), 3)"
)
ret <- reprex(input = input, styler = TRUE, render = FALSE)
ret <- reprex(input = input, styler = TRUE, advertise = FALSE, render = FALSE)
i <- which(ret == "#+ reprex-body")
expect_identical(ret[i + 1:2], input)
})

0 comments on commit e3ccba7

Please sign in to comment.