reproducible example (reprex)

install once per computer

install.packages("reprex")

or part of `tidyverse

install.packages("tidyverse")

You can either call it in every session

library(reprex)

or put it in .Rprofile for each machine to run whenever you open R

if (interactive()){
  suppressMessages(require(reprex))
}
options(
  reprex.advertise = FALSE, 
  reprex.si = TRUE, 
  reprex.style = TRUE,
  reprex.comment = "#;-",
  reprex.tidyverse_quiet = FALSE
)

to see your .Rprofile

usethis::edit_r_profile()

Since reprex is an interactive workflow package, don’t use this with dplyr, ggplot2, etc.

When ever you want to ask people about your code, or ask them to debug it

  1. Copy your code to clipboard
  2. Simply run in your console
reprex()


reprex(advertise = TRUE, # To suppress ads
       si = TRUE, # to include session info
       style = TRUE, # restyle your code
       tidyverse_quiet = TRUE # suppress tidyverse message
       )

Or instead of doing it manually, you can select your code, and under “Addins”. select “Render reprex”

Mike Nguyen, PhD
Mike Nguyen, PhD
Visiting Professor of Data Sciences and Operations

My research interests include marketing, and social science.

Next
Previous

Related