Skip to content

Reseting tinytheme() in sourced script yields LHS margin errors for _preceding_ plots #474

@grantmcdermott

Description

@grantmcdermott

It took me a while to isolate this down to a simple MWE, since I first observed the behaviour in a more complicated example. But consider the following script:

library(tinyplot)
tinytheme("classic")
tinyplot(I(mpg * 1000) ~ wt, data = mtcars)
# Reset the theme
tinytheme()

Running this code interactively works exactly as expected. However, if I source it by copying it and running reprex::reprex(), I get the following, with overlapping y-axis text:

library(tinyplot)
tinytheme("classic")
tinyplot(I(mpg * 1000) ~ wt, data = mtcars)

# Reset the theme
tinytheme()

Created on 2025-09-14 with reprex v2.1.1

The culprit appears to be that the LHS margin hasn't adjusted properly. What's truly odd here is that the problem only occurs if you reset the theme, i.e. call tinytheme() at the end. In other words, it somehow affects the preceding plot. (??) Compare the reprex::reprex() when I drop the last two lines:

library(tinyplot) 
tinytheme("classic")
tinyplot(I(mpg * 1000) ~ wt, data = mtcars)

Created on 2025-09-14 with reprex v2.1.1

Now, we get the expected display.

Off the bat, I genuinely don't understand what's causing this. But I did notice that this issue is also present in our ?tinytheme online documentation (and similarly if you source the examples locally):

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions