Record animation frames and insert them into a LaTeX document with the
animate package. Compile the document if an appropriate LaTeX command
is provided.
This is actually a wrapper to generate a LaTeX document using R. The document
uses the LaTeX package called animate to insert animations into PDF’s.
When we pass an R expression to this function, the expression will be
evaluated and recorded by a grahpics device (typically png and
pdf). At last, a LaTeX document will be created and compiled if
an appropriate LaTeX command is provided. And the final PDF output will be
opened with the PDF viewer set in getOption('pdfviewer') if
ani.options('autobrowse') == TRUE.
library(animation)
## brownian motion: note the 'loop' option in ani.opts and the careful settings
## in documentclass
saveLatex({
par(mar = c(3, 3, 1, 0.5), mgp = c(2, 0.5, 0), tcl = -0.3, cex.axis = 0.8, cex.lab = 0.8,
cex.main = 1)
brownian.motion(pch = 21, cex = 5, col = "red", bg = "yellow", main = "Demonstration of Brownian Motion")
}, img.name = "BM", ani.opts = "controls,loop,width=0.95\\textwidth", latex.filename = "brownian_motion.tex",
interval = 0.1, nmax = 10, ani.dev = "pdf", ani.type = "pdf", ani.width = 7,
ani.height = 7, documentclass = paste("\\documentclass{article}", "\\usepackage[papersize={7in,7in},margin=0.3in]{geometry}",
sep = "\n"))
## the PDF graphics output is often too large because it is uncompressed; try
## the option ani.options('pdftk') or ani.options('qpdf') to compress the PDF
## graphics; see ?pdftk or ?qpdf and ?ani.options
Donate
As a freelancer (currently working as a contractor) and a dad of three kids, I truly appreciate your donation to support my writing and open-source software development! Your contribution helps me cope with financial uncertainty better, so I can spend more time on producing high-quality content and software. You can make a donation through methods below.
-
Venmo:
@yihui_xie, or Zelle:xie@yihui.name -
Paypal
-
If you have a Paypal account, you can follow the link https://paypal.me/YihuiXie or find me on Paypal via my email
xie@yihui.name. Please choose the payment type as “Family and Friends” (instead of “Goods and Services”) to avoid extra fees. -
If you don’t have Paypal, you may donate through this link via your debit or credit card. Paypal will charge a fee on my side.
-
-
Other ways:
WeChat Pay (微信支付:谢益辉) Alipay (支付宝:谢益辉) 

When sending money, please be sure to add a note “gift” or “donation” if possible, so it won’t be treated as my taxable income but a genuine gift. Needless to say, donation is completely voluntary and I appreciate any amount you can give.
Please feel free to email me if you prefer a different way to give. Thank you very much!
I’ll give back a significant portion of the donations to the open-source community and charities. For the record, I received about $30,000 in total (before tax) in 2024-25, and gave back about $15,000 (after tax).