so what do i use r for?

an overview and some examples

R
physics
Author

baptiste

Published

March 10, 2019

Yesterday at the WIDS conference, I found myself trying to explain why I was there, and the first response I came up with was that I’ve been using R for about 13 years — not really an explanation, so of course someone followed-up by asking me what exactly is it I do with R (I’m a physicist). Here’s what I could have answered. A more complete version of my interactions with R is in this other blog post.

this post provided to you by R (quarto)

this post provided to you by R (quarto)

Pictorial examples of use, from left to right and column-wise: Rmd CV, photography portfolio, hobbies, md posters, tutorials and presentations, Shiny apps, exploratory analysis of experimental data, numerical simulation, and graphics.

Pictorial examples of use, from left to right and column-wise: Rmd CV, photography portfolio, hobbies, md posters, tutorials and presentations, Shiny apps, exploratory analysis of experimental data, numerical simulation, and graphics.

scripting

Familiarity with the language is the main reason I use R for all kinds of scripting and batch-processing jobs. Any language would do, and I’ve used many — bash, ruby, python, gnuplot, … — but R is quite versatile and can easily be used as a wrapper for other tools, such as pandoc, latex, etc. In combination with Rstudio’s support for R markdown, the fine customisation allowed by yaml proves to be a very powerful and efficient workflow to automate all kinds of tasks, which may not seem related to R at all. I’ll mention,

gandalf’s CV

gandalf’s CV

I also use R markdown for lecture slides, assignments, general correspondence, seminar announcements, etc.

hobbies

There’s certainly a fun aspect in playing with some packages such as my experiments with rayshader, this blog, answering too many SO questions and developing obscure hacks in grid graphics.

photography portfolio

photography portfolio

presentations

Although I do not tend to use R for my presentations (aside from lecture slides), I’ve given a number of presentations and turorials about graphics, heavily inspired by the concepts from ggplot2 and R graphics in general (as well as wisdom from the community).

Unexpected journey in the land of graphics

Unexpected journey in the land of graphics

exploratory data analysis

OK, I guess we’re slowly heading towards the more obvious — yes, I do use R in my research also. I’ve analysed hundreds of thousands of spectra, images, fitted models, I’ve made plots (lots and lots of them), etc. More recently I’ve started making use of shiny to create interactive apps that complement research papers or help non-programmers explore numerical simulations.

Data, data, and science

Data, data, and science

graphics

R is not an obvious choice for a physicist, and it certainly was even less obvious 13 years ago, but its first-class graphics were the first thing that appealed to me (as a Matlab user). I’ve become quite involved in the grid graphics system, with numerous packages developed over the years, most of them around ggplot2.

graphics addiction

graphics addiction

numerical simulations

The major sticking point in comparison to Matlab for a physicist is that numerical simulations in R are painfully slow. In fact, I often have two or three versions of the same code, one in R, one in Rcpp, and one in Matlab (Matlab wins, because of its use of Intel’s MKL). That being said, I’ve been an early adopter and happy user of Rcpp and RcppArmadillo, and most of my numerical simulations use them.

Simulations with Rcpp, 3D picture with rgl and mitsuba

Simulations with Rcpp, 3D picture with rgl and mitsuba

Last Updated: r format(Sys.Date(), format="%d %B %Y")

Reuse