Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Description: Convenience wrapper that uses the 'rmarkdown' package to
License: MIT + file LICENSE
URL: https://reprex.tidyverse.org, https://github.com/tidyverse/reprex
BugReports: https://github.com/tidyverse/reprex/issues
Depends:
Depends:
R (>= 4.1)
Imports:
Imports:
callr (>= 3.6.0),
cli (>= 3.2.0),
clipr (>= 0.4.0),
Expand All @@ -40,17 +40,18 @@ Imports:
rstudioapi,
utils,
withr (>= 2.3.0)
Suggests:
Suggests:
covr,
fortunes,
gh,
miniUI,
rprojroot,
sessioninfo,
shiny,
spelling,
styler (>= 1.2.0),
testthat (>= 3.2.1)
VignetteBuilder:
VignetteBuilder:
knitr
Config/Needs/website: dplyr, tidyverse/tidytemplate
Config/testthat/edition: 3
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export(reprex_rescue)
export(reprex_rtf)
export(reprex_selection)
export(reprex_slack)
export(upload_gist)
import(fs)
import(rlang)
importFrom(glue,glue)
Expand Down
25 changes: 14 additions & 11 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# reprex (development version)

* Adds `upload_gist()` to upload reprex to GitHub gists (#481, @tanho63)
* `reprex(html_preview = FALSE)` now properly avoids opening a preview window, which flows nicer with `upload_gist()` usage.

# reprex 2.1.1

* `reprex(style = FALSE)` will never nag about installing styler (#461).
Expand Down Expand Up @@ -59,16 +62,16 @@ Specifically, this applies to use on RStudio Server and RStudio Cloud.
un-`reprex()` functions, such as `reprex_clean()`.
* In this context, the file containing the (un)rendered reprex is opened so the
user can manually copy its contents.

## Filepaths

`wd` is a new argument to set the reprex working directory.
As a result, the `outfile` argument is deprecated and the `input` argument has new significance.
Here's how to use `input` and `wd` to control reprex filepaths:

* To reprex in the current working directory,
Previously: `reprex(outfile = NA)`
Now: `reprex(wd = ".")`
* To reprex in the current working directory,
Previously: `reprex(outfile = NA)`
Now: `reprex(wd = ".")`
More generally, usage looks like `reprex(wd = "path/to/desired/wd")`.
* If you really care about reprex filename (and location), write your source to
`path/to/stuff.R` and call `reprex(input = "path/to/stuff.R")`. When `input`
Expand Down Expand Up @@ -199,7 +202,7 @@ R 3.1 and R 3.2 are no longer explicitly supported or tested. Our general practi

reprex has a website: <https://reprex.tidyverse.org>. It includes a contributed article from @njtierney (#103).

reprex has moved to the [tidyverse Organization](https://github.com/tidyverse). It is installed as part of the [tidyverse meta-package](https://www.tidyverse.org) and is [suggested to those seeking help](https://www.tidyverse.org/help/).
reprex has moved to the [tidyverse Organization](https://github.com/tidyverse). It is installed as part of the [tidyverse meta-package](https://www.tidyverse.org) and is [suggested to those seeking help](https://www.tidyverse.org/help/).

`reprex()` gains several arguments and many arguments can now be controlled via an option, in case a user wants their own defaults.

Expand All @@ -224,21 +227,21 @@ These look like `reprex(..., arg = opt(DEFAULT), ...)` in the help file. This is
* Line wrapping is preserved from source via a Pandoc option (#145 @jimhester, #175).

* `venue = "gh"` now targets CommonMark as the standard for GitHub Flavored Markdown (#77).

* `venue = "so"` has appropriate whitespace at the start.

* `venue = "ds"` is a new value, corresponding to <https://www.discourse.org>, which is the platform behind [community.rstudio.com](https://forum.posit.co/). This is currently just an alias for the default `"gh"` GitHub venue, because the formatting appears to be compatible. Adding the `"ds"` value so Discourse can be documented and to guard against the possibility that some formatting is actually unique.

## Other changes

* The `keep.source` option is set to `TRUE` when rendering the reprex, so reprexes involving srcrefs should work (#152).

* The "undo" functions (`reprex_invert()`, `reprex_clean()`, `reprex_rescue()`) handle `input` and `outfile` like `reprex()` does. The `outfile` argument is new (#129, #68).

* The default value for knitr's `upload.fun` is now set according to the venue. It is `knitr::imgur_upload()` for all venues except `"r"`, where it is `identity` (#125).

* The HTML preview should appear in the RStudio Viewer more consistently, especially on Windows (#75 @yutannihilation).

* More rigorous use of UTF-8 encoding (#76 @yutannihilation).

* Expression input handling has been refactored. As a result, formatR is no longer Suggested. Trailing comments -- inline and on their own line -- are also now retained (#89, #91, #114, @jennybc and @jimhester).
Expand Down Expand Up @@ -273,13 +276,13 @@ This was a non-functioning release created by CRAN maintainers by commenting out

* `reprex()` gains optional arguments `opts_chunk` and `opts_knit`, taking named list as input, in order to supplement or override default knitr chunk and package options, respectively. (#33)
- This made the explicit `upload.fun` argument unnecessary, so it's gone. The `upload.fun` option defaults to `knitr::imgur_upload`, which means figures produced by the reprex will be uploaded to [imgur.com](https://imgur.com/) and the associated image syntax will be put into the Markdown, e.g. `![](https://i.imgur.com/QPU5Cg9.png)`. (#15 @paternogbc)

* Order of `reprex()` arguments has changed.

* `reprex()` gains the `si` argument to request that `devtools::session_info()` or `sessionInfo()` be appended to reprex code (#6 @dgrtwo). When `si = TRUE` and `venue = "gh"` (the default), session info is wrapped in a collapsible details tag. See [an example](https://github.com/tidyverse/reprex/issues/55) (#55).

* Reprex code can be provided as an R expression. (#6 @dgrtwo, #35)

* `reprex()` uses clipboard functionality from [`clipr`](https://CRAN.R-project.org/package=clipr) and thus should work on Windows and suitably prepared Unix-like systems, in addition to Mac OS. (#16 @mdlincoln)

# reprex 0.0.0.9000
Expand Down
4 changes: 3 additions & 1 deletion R/reprex_impl.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ reprex_impl <- function(
# i.e., consider if the user provided any path info
reprex_path("Writing reprex file:", reprex_file)
}
expose_reprex_output(reprex_file, rtf = (venue == "rtf"))
if (html_preview || reprex_clipboard()) {
expose_reprex_output(reprex_file, rtf = (venue == "rtf"))
}
invisible(read_lines(reprex_file))
}

Expand Down
60 changes: 60 additions & 0 deletions R/reprex_upload.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#' Upload reprex as gist
#'
#' Uses [`gh::gh()`] to upload a reprex to GitHub gists.
#'
#' @param reprex character: reprex as created by [`reprex()`]
#' @inheritDotParams gh::gh
#' @param gist_description character: description of gist, default ""
#' @param file_name character: file_name to create, default NULL will generate
#' random filename
#' @param public boolean: whether to make gist public, default TRUE
#'
#' @seealso <https://docs.github.com/en/rest/gists/gists?apiVersion=2022-11-28#create-a-gist>
#' @family upload
#'
#' @examplesIf interactive()
#' reprex(print(pi), html_preview = FALSE) |>
#' upload_gist()
#'
#' @return uploads to GitHub gist and invisibly returns URL of created gist
#' @export
upload_gist <- function(
reprex,
...,
gist_description = "",
file_name = NULL,
public = TRUE
) {
rlang::check_installed("gh")

if (is.null(file_name)) {
file_name <- paste0(
format(Sys.Date(), format = "%Y%m%d"),
"_",
sample(adjective_animal, 1),
".R"
)
}

stopifnot(
is.character(reprex) && length(reprex) > 0,
is_string(file_name),
is_string(gist_description),
is_bool(public)
)

gist_info <- gh::gh(
"POST /gists",
public = public,
description = gist_description,
files = setNames(
list(list(content = paste(reprex, collapse = "\n"))),
file_name
),
...
)

cli::cli_alert_success("Uploaded reprex to {.url {gist_info$html_url}}")

return(invisible(gist_info$html_url))
}
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ reference:
- reprex_addin
- reprex_venue
- reprex_locale
- upload_gist
- title: Going backwards
contents:
- reprex_clean
Expand Down
95 changes: 95 additions & 0 deletions man/upload_gist.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading