How to overwrite reprex uploading to imgur

I manage a R programming environment for a group of users at my company. We often work with sensitive data, and some of my data scientists have started using the reprex package in R.

It's a great little package, but I noticed the package by default uploads images to imgur when you call it. This would be problematic for us if one of our users accidentally uploaded something sensitive.

Would there be a way to change this default for all users perhaps in a or via some setting in RStudio?

Looks like you can disable upload to imgur with venue = "r" option in reprex:

Right, I saw that. One can also change the knitr setting that reprex changes at run-time using: knitr::opts_knit$set( = identity).

My question is: How can I make this the default for all users so nobody accidentally uploads a sensitive image/graph to imgur?

Fork the project. Change the default.
Have them use josephreprex instead of 'reprex'

If you can modify .Rprofile for them, you can set this option there. Or you can set an alias there with default venue set, using, for example, purrr::partial or something similar.

For a variety of reason, I don't think that will work too well unfortunately.

Could you provide a code example of what you're talking about? How would I specifically set the default venue function option in Or even set knitr::opts_knit$set( = identity) (although this would be much harder given that this isn't a function option but something reprex() does it seems).

Or the other option, could you provide a code example of that using purrr::partial?

You'd put something like this into .Rprofile:

reprex <- purrr::partial(reprex::reprex, venue = "r")

You then use it as usual with copying something like this:

ggplot(mtcars, aes(x = as.factor(cyl), y = mpg)) +

When you run reprex() it'll produce following output:

> reprex()
Rendering reprex...
Rendered reprex is on the clipboard.
[1] "library(ggplot2)"                                                    
[2] "ggplot(mtcars, aes(x = as.factor(cyl), y = mpg)) +"                  
[3] "  geom_boxplot()"                                                    
[4] ""                                                                    
[5] "#' ![](reprex_reprex_files/figure-markdown_strict/reprex-body-1.png)"

This, of course, means that pictures will need to be attached somehow to reports, but that is left as an exercise to the reader :slight_smile:

Ahhh. I see. Thank you for that. That is helpful.

For clarification if I do something like: reprex::reprex() or


your solution will not work, correct?

Yes, you are right.

Second case you can prevent by calling library(reprex) in your .Rprofile. Then overwriting reprex with partial will be first on a search path. Not sure how to go around reprex::reprex() route without messing too much with environments and stuff. At the end of the day there will be some need for education of the masses on the danger of sharing private data :slight_smile:

Thank you for this. This has been very informative. I'll also note this method doesn't work if users use reprex through the RStudio addins GUI (because under the hood it's using reprex::reprex()).

We will have to communicate to users to be careful.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.