From 8c64e133ac7050bad02151cfb511c138e0a6c30d Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Wed, 12 Sep 2018 16:07:08 -0700 Subject: [PATCH] Format the ad as superscript Closes #201 Consider superscript advertising as the default --- NEWS.md | 2 ++ R/whisker.R | 5 ++++- inst/templates/REPREX.R | 4 +--- tests/testthat/test-pandoc.R | 4 ++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index 436fe813..f078bab6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # reprex 0.2.0.9000 +* The reprex ad is formatted as superscript for `venue = "gh"` and `venue = "so"`, i.e. it is more subtle now (#201). + * New experimental venue "rtf" produces syntax highlighted snippets suitable for pasting into presentation software such as Keynote or PowerPoint. This venue is discussed in [an article](https://reprex.tidyverse.org/articles/articles/rtf.html) (#26). * Arguments `opts_chunk` and `opts_knit` have been removed from `reprex()`. The same effect has always been achievable via roxygen comments in the reprex code and the examples have always demonstrated this. Overriding knitr options doesn't seem to come up often enough in real-world `reprex()` usage to justify these arguments. diff --git a/R/whisker.R b/R/whisker.R index ed7ce372..9ea33d9d 100644 --- a/R/whisker.R +++ b/R/whisker.R @@ -4,7 +4,7 @@ apply_template <- function(x, reprex_data = NULL) { tidyverse_quiet = as.character(tidyverse_quiet), comment = comment, upload_fun = "knitr::imgur_upload", - advertise = advertise + ad = "Created on `r Sys.Date()` by the [reprex package](https://reprex.tidyverse.org) (v`r utils::packageVersion(\"reprex\")`)" )) if (!is.null(reprex_data$std_file)) { @@ -25,6 +25,7 @@ apply_template <- function(x, reprex_data = NULL) { if (reprex_data$venue == "gh") { data$si_start <- prose("
Session info") data$si_end <- prose("
") + data$ad <- paste0("", data$ad, "") } if (reprex_data$venue == "so") { @@ -32,12 +33,14 @@ apply_template <- function(x, reprex_data = NULL) { data$so_syntax_highlighting <- prose("") ## empty line between html comment re: syntax highlighting and reprex code x <- c("", x) + data$ad <- paste0("", data$ad, "") } if (reprex_data$venue == "r") { data$upload_fun <- "identity" } + data$ad <- if (reprex_data$advertise) prose(data$ad) else NULL data$body <- paste(x, collapse = "\n") whisker::whisker.render(read_template("REPREX"), data = data) } diff --git a/inst/templates/REPREX.R b/inst/templates/REPREX.R index 4945138d..d6ef10e3 100644 --- a/inst/templates/REPREX.R +++ b/inst/templates/REPREX.R @@ -12,9 +12,7 @@ knitr::opts_knit$set(upload.fun = {{{upload_fun}}}) {{{std_file_stub}}} -{{#advertise}} -#' Created on `r Sys.Date()` by the [reprex package](https://reprex.tidyverse.org) (v`r utils::packageVersion("reprex")`). -{{/advertise}} +{{{ad}}} {{#si}} {{{si_start}}} diff --git a/tests/testthat/test-pandoc.R b/tests/testthat/test-pandoc.R index 50a30751..0cd0530a 100644 --- a/tests/testthat/test-pandoc.R +++ b/tests/testthat/test-pandoc.R @@ -3,9 +3,9 @@ context("pandoc") test_that("pandoc does not add hard linebreak in the ad", { skip_on_cran() out <- reprex(input = "1:3\n", venue = "gh", show = FALSE, advertise = TRUE) - expect_match(out[length(out)], "^Created on") + expect_match(out[length(out)], "Created on") out <- reprex(input = "1:3\n", venue = "so", show = FALSE, advertise = TRUE) - expect_match(out[length(out)], "^Created on") + expect_match(out[length(out)], "Created on") }) test_that("pandoc version checkers don't error", {