-
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
fling reprex on the internet e.g. as a gist #190
Comments
It would be great to be able to post a full reprex outside of issues in a specific repo. A gist is a great solution for this. |
It also reminds me of https://github.com/ropenscilabs/codefinch |
I keep rediscovering this issue when I want to post a standalone reprex. What do you think @jennybc? |
Yeah I'm in favour of this. Thought dump: it would be interesting if your source code went up into the gist, but also the rendered product for one or more venues. |
Possibly relevant/useful https://github.com/MilesMcBain/gistfo |
OK I can work on this if it is getting interest. |
We can discuss design here. For example, I am generally anti-gist because notifications don't work, among other things. I frequently end feeling like it's GitHub-lite, but in a bad way. So I'd like to explore the pros/cons of targeting a gist vs. a GitHub repo. Pros for GitHub repo: all sorts of existing tooling (technical and mental) works as usual. Cons for GitHub repo: would this lead to unsavory proliferation of repos? When people use a gist vs gh repo, is this one of their motivations, i.e. to reduce clutter? Pros for gist: I suspect there are existing tools that integrate better with gists than gh repos. But does that matter to us? Morally, reprexes certainly feel like what gists are for. Probably easier to create. Cons for gist: git/github-lite. No notifications, making conversation around a "reprex as gist" essentially impossible. |
I semi-frequently want to provide a reprex with some demonstration code and send it to someone in rendered form. But this code isn't really associated with any particular repo—i.e., I'm not raising an "issue", just want to share something. I suppose I could setup a personal repo called "reprexes" and post these types of things there. Or maybe there should be a communal version of this somewhere? E.g. in the tidyverse org? This would solve the unwanted ephemeral nature of one-off reprex posts as gists. |
I think, if gh repo were the target, it would have to be at the user-level (versus some large communal bucket). I have contemplated doing this sort of thing for local/personal reasons anyway. Sometimes I wish I had a central record of my reprexes (or, at least, some of them). |
Personally I use a gist to take some note or save some snippets I want to share or remember, specifically when those are not associated with any repo. Often (if not all the time), if the gist is shared, the link is posted in a conversation (github, community.rstudio.com, SO, ...). The discussion, if any, happens in this other site and not in the gist website. I find that reprex is like a snippet and should be share in something like a gist. For me Github repo are for larger piece of code, and I associate it with a project.
I guess It could make sense to adapt the workflow and to have a central repo as user where to store reprex, with an associated project. I know some people have a central repo for presentation or for saving notes. I agree that this should be per user and not central. (like one reprex repo configured as an option to use with the 📦 for all the reprexes) I find the tool for gist useful (gistr 📦) but it is a different approach than github and existing tools around R workflow with git. One way to tackle this is also to see what would be bundled in the shared reprex for this feature: the code source and an rendering ? with images ? several rendering ? several formats (R scripts, Rmd, md, html ?). Depending on this, and how far we go from a snippet to a small reproducible project, gist would be less ok and github would be prefered. |
Ok let's go with the gist version of this. Perhaps it could start as a PR for an article that explores a few scenarios of putting code in a gist along with various products, like a rendered version, figs, etc. Then it would be much easier to decide if wrapping this into a function -- and a function that lives here -- is the way to go. |
I had a bit of a look through this. Creating gists would also require a GITHUB_PAT to be specified that has sufficient scoping to create new gists. Some minor path changes to the knitted resources would also be needed, as gists are flat structures. |
Does anyone know how gist pulls the print output from Python (e.g. Jupyter) Notebooks and includes that in what it renders? |
A proof of concept with Then a gist is defined with the code as a file, while the markdown output is posted as a comment allowing the rendering for tables, figures, etc. It could be a new venue. I am happy to make a PR, if the following example suits well the purpose. input <- c(
"#' Hello world",
"## comment",
"1:5"
)
(output <- reprex::reprex(input = input, venue = "gh", html_preview = FALSE))
#> i Rendering reprex...
#> CLIPR_ALLOW has not been set, so clipr will not run interactively
#> [1] "Hello world"
#> [2] ""
#> [3] "``` r"
#> [4] "## comment"
#> [5] "1:5"
#> [6] "#> [1] 1 2 3 4 5"
#> [7] "```"
#> [8] ""
#> [9] "<sup>Created on 2021-04-11 by the [reprex package](https://reprex.tidyverse.org) (v2.0.0)</sup>"
(file_id <- sprintf("%s-%s.R", sample(reprex:::adjective_animal, 1), as.character(as.integer(Sys.time()))))
#> [1] "steep-carp-1618149950.R"
gist_info <- gh::gh(
"POST /gists",
public = "true",
files = `names<-`(
list(list("content" = paste(input, collapse = "\n"))),
file_id
)
)
gist_comment <- gh::gh(gist_info$comments_url, .method = "POST", body = paste(output, collapse = "\n"))
sprintf("https://gist.github.com/%s/%s/", gh::gh_whoami()$login, gist_info$id)
#> [1] "https://gist.github.com/mcanouil/3a55759930cfb70f382cf3e68c4b81d0/" |
Code snippet exchange are being quite popular as reprex for issue filing, shared example or other needs. Currently, they are published most often on SO, GH and Rstudio community, and mainly used as minimal reprex, so short snippet.
Sometimes, reprex can be long on purpose (not minimal reprex) and it could worth being published online for isolation, reuse or just clarity.
A gist seems to me very similar to a code snippet or example, and I used some gist sometimes for that. I think it could be interesting to be able to publish a reprex as a gist containing the source code and the files to create the reprex.
There is one example in this gist where I wanted to publish some code examples online, related to this discussion but outside. For this one, I took the yaml front matter used for reprex to generate the md file and use
gistr
📦 to render and publish, as this package has rendering hability like reprex.In this case, the R script and the md file are published in the same gist. Reprex is a great way to create quickly a reproductible code using R code and markdown, even for long script. Using Rmd format could have been another way, publish the Rmd file and the md output. But it felt easier to use reprex.
I think it could be useful to have in reprex such a feature of pusblishing results as a gist and retrieve the url to copy-paste somewhere. This would help sharing reprex more easily, even for minimal reprex.
What do you think on this feature ? Is a gist the correct tool for publishing ?
For this
gistr
can help andgistfo
can be of inspiration.Questions identified:
I can work further on something (i.e a POC) if you want.
The text was updated successfully, but these errors were encountered: