Building notes: The infamous sticky note from Sex and the City and R
Some women walk away from their bugs. I turned mine into visual commentary. And just like that, it wasted HOURS of my life!
As an aside, I’m a huge Sex and the City (SATC) fan. Carrie Bradshaw, in all her flawed glory, brings me absolute joy, and I love her iconic voiceovers. For a while, I considered making this blog Carrie Bradshaw-themed, writing it in the style of her newsletters:

Anyway, a quick explanation of Sex and the City lore: our heroine, Carrie Bradshaw, is with a man who breaks up with her by leaving in the middle of the night and letting her find the infamous break-up sticky note in the morning:
This made me think of two things:
When I ran simulations on my laptop overnight, there were times I’d wake up in the morning to find it had crashed or encountered an error. It was absolutely the worst!!
I actually found out that the second year of my postdoc contract was no longer funded a month before it was supposed to be renewed—through a sticky note (long story).
So as kind of a make lemonade from lemon situations, I decided to see if I can make a sticky note pop up every time R gives me an error!
Building it
So the first thing that I Googled was… how do I even make an image pop up in Rstudio?
And someone on Stackoverflow had the exact same question:
I still don’t quite understand what {magick} does. I only know it for making animation in base plot (if you’re a ggplot2 user, you would be using the gganimate package).
Ok so I guess I’ll save the sticky note as a .png file!
Cool I got the sticky note to pop up in all of its glory.
For making it appear every time there’s an error, we probably want to tinker around with the options in R. Looking through the documentation…this is what we needed:
options(warning.expression = quote(print(img)))This is saying with the warning, print out the sticky note to the Viewer pane!
And it works when I do log(-1) , but when I tried it with a different test case:
test_df <- data.frame(1:5)
test_df[6] <- NA This prints out the warning message and NOT the image. Ok I think it’s because it’s an error message that is different than a warning message, so I added this in:
options(warning.expression = quote(plot(img)),
error = quote(plot(img)))Aha it works! I can now emotionally devastate myself when I made little coding errors!
library(magick)
img_path <- "~/Desktop/stickynote.png"
img <- magick::image_read(img_path)
img
options(warning.expression = quote(plot(img)),
error = quote(plot(img)))
#Test cases
#Warning
log(-1)
#Error
test_df <- data.frame(1:5)
test_df[6] <- NA
Addendum
Out of curiosity, I wanted to see if it works with gifs. So using GIPHY I made this:
Ok, so this was a bit harder than I thought because you can’t just plot a .gif in the regular plots tab. You need to use the Viewer (which is useful for gganimate, previewing Quarto websites, etc.). This was a struggle until I came across this post:
And if you scroll down to the last answer, the responder actually has a personal package with his own script:
And going to his Github repo! I copied and pasted:
And after an hour of trying to figure this out:
It’s amazing how little stupid projects actually taught me a lot!
Here I leave a code:
rstudio_viewer <- function(file_name, file_path = NULL) {
temporary_file <- tempfile()
dir.create(temporary_file)
html_file <- file.path(temporary_file, file_name)
current_path <- ifelse(is.null(file_path),
getwd(),
path.expand(file_path)
)
file.copy(file.path(current_path, file_name), html_file)
rstudioapi::viewer(html_file)
}
options(
warning.expression = quote(rstudio_viewer("giphy.gif")),
error = quote(rstudio_viewer("giphy.gif"))
)
# Test cases
# Warning
log(-1)
# Error
test_df <- data.frame(1:5)
test_df[6] <- NA
And I leave it with a Carrie Bradshaw quote:
There is a good way to break up with someone, and it doesn’t involve a Post-It!









