From e3ccba7627b53600b61ec8c07872b232ee90fc4e Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Wed, 11 Oct 2017 18:07:02 -0700 Subject: [PATCH] Plan B: put reprex_info() at top of body --- R/reprex-info.R | 5 +++-- R/reprex.R | 4 +++- inst/templates/REPREX.R | 2 -- tests/testthat/test-styler.R | 3 ++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/R/reprex-info.R b/R/reprex-info.R index cc7383e0..be73140e 100644 --- a/R/reprex-info.R +++ b/R/reprex-info.R @@ -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() } diff --git a/R/reprex.R b/R/reprex.R index 6f4ecdaf..f8659cd1 100644 --- a/R/reprex.R +++ b/R/reprex.R @@ -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)) { @@ -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, diff --git a/inst/templates/REPREX.R b/inst/templates/REPREX.R index be446c45..d224fde3 100644 --- a/inst/templates/REPREX.R +++ b/inst/templates/REPREX.R @@ -9,8 +9,6 @@ knitr::opts_knit$set(upload.fun = knitr::imgur_upload) {{{user_opts_chunk}}} {{{user_opts_knit}}} -{{advertisement}} - #+ reprex-body {{{body}}} diff --git a/tests/testthat/test-styler.R b/tests/testthat/test-styler.R index 317b6947..f8c67f42 100644 --- a/tests/testthat/test-styler.R +++ b/tests/testthat/test-styler.R @@ -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") @@ -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) })