-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Capture reprex directly from GitHub issue or SO post #67
Comments
That's a nice idea! |
Possible name:
|
URL should be fine. I can imagine a use case where I get a GH issue number out of thin air, e.g. a test comment, but then I could also call |
+1 for opening a new file with the results |
I'd be happy to take a stab at this issue. I have two questions though:
|
I would probably do something like this:
|
So just to be clear, I like the idea of using |
I suspect it might be tricky to isolate the reprex from, say, the entire issue comment and "just" run it. That's why I assumed the first draft of this would dump contents into a file and open it. Seems unavoidable that you'll need That's going to be an intermediate step anyway, so I guess you'll find out 😄 Agree that your suggestion of accepting a URL as |
#199 has a first pass at implementing
Line 180 in 0eec4b6
…This means that some formatting (e.g., indentation of library(reprex)
reprexed <- reprex({
library(magrittr)
mtcars[, 1:2] %>%
head(n = 1)
})
#> Rendering reprex...
#> Rendered reprex is on the clipboard.
print(reprex_invert(reprexed))
#> Clean code is on the clipboard.
#> [1] "library(magrittr)"
#> [2] "mtcars[, 1:2] %>%"
#> [3] "head(n = 1)"
#> [4] "#' Created on 2018-08-31 by the [reprex"
#> [5] "#' package](http://reprex.tidyverse.org) (v0.2.0)." Created on 2018-08-31 by the reprex package (v0.2.0). Do you want me to open a separate issue for this or just include the fix in #199 ?
I think if we’re going to offer to open the file for the user once Lines 362 to 377 in 0eec4b6
For example, I was wondering why
|
I'm about to leave on a big trip, so I can't review quickly. Feel free to nudge me in a week or so. I have clean up I want to do re: the undo functions anyway. I'm not surprised you found something that seems a bit odd. |
I have done the cleanup in the undo functions and it did fix the indentation-stripping problem you pointed out (a85849d). |
Re: opening a file with the output. Maybe it does make sense to do this (or offer to do this) more often. Agree the behaviour should be as consistent as possible across all the functions. In In the undo functions, yes perhaps it should just be the default. It is different from |
@DavisVaughan basically just 👍 this in weekly meeting |
I am guessing the idea is to do something like my reprex below? url <- "https://github.com/tidyverse/dplyr/issues/5849"
issue_json <- gh::gh(sub("https*://github.com", "/repos", url))
issue_text <- unlist(strsplit(issue_json$body, "\r\n"))
(reprex::reprex_invert(input = issue_text))
#> CLIPR_ALLOW has not been set, so clipr will not run interactively
#> [1] "#' This works and gives the expected result:"
#> [2] ""
#> [3] "my_summarise5 <- function(data, mean_var ) {"
#> [4] " data %>% "
#> [5] " mutate(\"mean_{{mean_var}}\" := mean({{ mean_var }}),"
#> [6] " across(last_col(), ~.+1, .names = \"{col}_plusone\"))"
#> [7] "}"
#> [8] ""
#> [9] "mtcars %>% my_summarise5(cyl) %>% head"
#> [10] ""
#> [11] "#' giving:"
#> [12] ""
#> [13] " mpg cyl disp hp drat wt qsec vs am gear carb mean_cyl mean_cyl_plusone"
#> [14] "Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4 6.1875 7.1875"
#> [15] "Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4 6.1875 7.1875"
#> [16] "Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1 6.1875 7.1875"
#> [17] "Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1 6.1875 7.1875"
#> [18] "Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2 6.1875 7.1875"
#> [19] "Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1 6.1875 "
#> [20] ""
#> [21] "#' but it would have been nicer to be able to be able to refer to the columns directly like this:"
#> [22] ""
#> [23] "my_summarise5 <- function(data, mean_var ) {"
#> [24] " data %>% "
#> [25] " mutate(\"mean_{{mean_var}}\" := mean({{ mean_var }}),"
#> [26] " across(\"mean_\"{{mean_var}}\", ~.+1, .names = \"mean_{{mean_var}}_plusone\"))"
#> [27] "}"
#> [28] ""
#> [29] "#' or "
#> [30] ""
#> [31] "my_summarise5 <- function(data, mean_var ) {"
#> [32] " data %>% "
#> [33] " mutate(\"mean_{{mean_var}}\" := mean({{ mean_var }}),"
#> [34] " \"mean_{{mean_var}}_plusone\" := across(\"mean_{{mean_var}}) + 1)"
#> [35] "}"
#> [36] ""
#> [37] "#' neither of which work." |
Intended usage:
reprex_invert("rstats-db/DBI#153")
.Slightly related: I wouldn't mind if RStudio opened a new file with the results as a side effect.
The text was updated successfully, but these errors were encountered: