Skip to content

too-small interval gives puzzling error #123

@MichaelChirico

Description

@MichaelChirico

I was trying to plot many frames and target the output to be a certain length (5 seconds):

nn = 720L
saveGIF({for (ii in 1:nn) plot(1:10)}, interval = 5/nn)

This then failed:

Error in if (100%%fps) stop("argument 'fps' must be a factor of 100") : 
  argument is not interpretable as logical

Quite strange. However, the stack trace gives a lot clearer understanding:

4: magick::image_animate(img, loop = loop, fps = 100/as.integer(interval * 
       100), dispose = dispose)
3: magick.convert(files = files, output = output, loop = loop, interval = interval, 
       dispose = dispose)
2: im.convert(img.files, output = path.expand(movie.name), convert = convert, 
       cmd.fun = cmd.fun, clean = clean, extra.opts = extra.opts)
1: saveGIF({
       for (ii in seq_along(grd)) {
           t = grd[ii]
           par(oma = c(0.1, 0.1, 0.1, 0.1))
           plot(NA, xlim = c(-e, e), ylim = c(-e, e), asp = 1, axes = FALSE, 
               xlab = "", ylab = "")
           lines(a * cos(grd), a * sin(grd), lty = 2L)
           x0 = a * cos(t)
           y0 = a * sin(t)
           segments(0, 0, x0, y0)
           lines(x0 + b * cos(grd), y0 + b * sin(grd), lty = 3L)
           points(a * cos(t) - b * sin(t), a * sin(t) + b * cos(t), 
               pch = 19L, col = "red")
           segments(x0, y0, x0 + b * cos(t + pi/2), y0 + b * sin(t + 
               pi/2))
           lines(r * cos(grd[1:ii] - t0), r * sin(grd[1:ii] - t0))
       }
   }, interval = 5/nn)

In particular:

100/as.integer(interval * 100)

Will give Inf since interval < 1/100 so as.integer will truncate to 0.

It would be helpful if this were pointed out sooner

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