Articles by Code R

Make error messages your own

July 12, 2021 | Code R

The stop() function allows you to terminate the execution of a function if there is a fatal problem. For example, imagine this code that calculates the square root of a number but only if the input number is positive. real_root [Read more...]

The new R pipe

May 24, 2021 | Code R

R 4.1.0 is out! And if version 4.0.0 made history with the revolutionary change of stringAsFactors = FALSE, the big splashing news in this next version is the implementation of a native pipe. The new pipe The “pipe” is one of the most distinctive qualities of tidyverse/dplyr code. I’m sure you’... [Read more...]

Star Trek ratings on IMDB

March 8, 2021 | Code R

My girlfriend and I are watching Star Trek: The Next Generation (TNG). The first season it’s pretty lame, but it gets better further down the line. That piqued my curiosity – is that impression shared by the rest of The Internets? So I decided to d...
[Read more...]

Rammstein vs. Lacrimosa

November 20, 2019 | Code R

Some time ago, someone I follow on twitter posted about having to buy a whole book with rules to tease out grammatical gender in German. Further down the replies, someone reminisced about trying (and failing) to learn German just by listening to Rammstein’s lyrics. I studied about drei Jahre ...
[Read more...]

Rammstein vs. Lacrimosa

November 20, 2019 | Code R

Some time ago, someone I follow on twitter posted about having to buy a whole book with rules to tease out grammatical gender in German. Further down the replies, someone reminisced about trying (and failing) to learn German just by listening to Rammstein’s lyrics. I studied about drei Jahre ...
[Read more...]

Why I love data.table

July 5, 2019 | Code R

I’ve been an R user for a few years now and the data.table package has been my staple package for most of it. In this post I wanted to talk about why almost every script and RMarkdown report I write start with:
library(data.table)
My memory issues I started ...
[Read more...]

Why I love data.table

July 5, 2019 | Code R

I’ve been an R user for a few years now and the data.table package has been my staple package for most of it. In this post I wanted to talk about why almost every script and RMarkdown report I write start with: library(data.table) My memory issues ...
[Read more...]

Using ecmwfr to measure global warming

April 18, 2019 | Code R

For my research I needed to download gridded weather data from ERA-Interim, which is a big dataset generated by the ECMWF. Getting long term data through their website is very time consuming and requires a lot of clicks. Thankfuly, I came accross the nifty ecmwfr R package that allowed me ...
[Read more...]

Using ecmwfr to measure global warming

April 18, 2019 | Code R

For my research I needed to download gridded weather data from ERA-Interim, which is a big dataset generated by the ECMWF. Getting long term data through their website is very time consuming and requires a lot of clicks. Thankfuly, I came accross th...
[Read more...]

Statistical metamerism

January 2, 2019 | Code R

Summary The metamer package implements Matejka and Fitzmaurice (2017) algorithm for generating datasets with distinct appearance but identical statistical properties. I propose to call them “metamers” as an analogy with the colorimetry concept. Metamers in vision This is not a prism separating white light into its component wavelengths. It is an ...
[Read more...]

Multiple color (and fill) scales with ggplot2

September 17, 2018 | Code R

tl;dr: The functionality shown in this post is now on the ggnewscale package! ????. You can find the original code in this gist. A somewhat common annoyance for some ggplot2 users is the lack of support for multiple colour and fill scales. Perusing StackOverflow you can find many questions relating ...
[Read more...]

Wrapping around ggplot2 with ggperiodic

August 20, 2018 | Code R

As an atmospheric scientists, a lot of my research consists on plotting and looking at global fields of atmospheric variables like pressure, temperature and the like. Since our planet is a sphere (well, almost), it is unbound and so longitude is a periodic dimension. That is, to the right of 180°...
[Read more...]

How to make a generic stat in ggplot2

May 15, 2018 | Code R

For a while now I’ve been thinking that, yes, ggplot2 is awesome and offers a lot of geoms and stats, but it would be great if it could be extended with new user-generated geoms and stats. Then I learnt that ggplot2 actually has a pretty great extension system so ...
[Read more...]

How to make a shaded relief in R

February 3, 2018 | Code R

While trying to build a circular colour scale to plot angles and wind direction, I stumbled upon an easy way to make shaded reliefs in R. You known, when you look at cool maps of mountain areas where peaks and valleys are easily distinguishable from their shadows like this: What ...
[Read more...]

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)