remake icon indicating copy to clipboard operation
remake copied to clipboard

Reproducible plots with `jitter` in them

Open aammd opened this issue 9 years ago • 2 comments

When I jitter points in a plot, I often use set.seed so that the jitter behaviour doesn't change while I tweak other components of the figure. This works fine in a regular function, but when remake runs the function it behaves differently -- the seed is apparently not set.

Here is a reproducible example

writeLines(c("sources:", "  - myplot.R", "", "targets:", "  all:", "    depends: ", 
             "      - plot.png", "      ", "  plot.png:", "    command: myplot()", 
             "      ", "", "", ""), "remake.yml")

writeLines(c("myplot <- function(){", "  x <- 1:5", "  y <- x", "  plot(x, jitter(y, 3))", 
             "}"), "myplot.R")

remake::make() #plot
remake::make() #different plot!
remake::make() #different plot! 

in contrast

myplot <- function(){
  x <- 1:5
  y <- x
  set.seed(4812)
  plot(x, jitter(y, 3))
}

myplot()
myplot() # same

Is this a bug? While I'm curious to know if it can be fixed, I'm even more curious to know how it is possible in the first place!

aammd avatar Jun 07 '16 23:06 aammd

Would it be desirable to allow the seed to be set from remake.yml? something like

  plot.png:
    command: myplot()
    plot: true
    seed: 4812

aammd avatar Jun 07 '16 23:06 aammd

Try adding plot: true to your example and things work fine.

Arguably this is a different bug in remake; your file dependency plot.png did not produce a file. So when running a file target we should check that the file was actually created.

richfitz avatar Jun 08 '16 08:06 richfitz