I think you can use magick package to modify your original gif.
Something like:
library(magick)
gif <- image_read("https://jeroen.github.io/images/banana.gif")
# this is the original gif
gif
gif2 <- image_animate(gif, loop = 3)
# gif that will loop only two times
gif2
image_write(gif2, "new_banana.gif")
See
You have also so specific function gif that uses gifski
Hope it helps