Publications by Econometrics and Free Software

chronicler is now available on CRAN

17.05.2022

I am very happy to annouce that the {chronicler} package, which I’ve been working on for the past 3 months has been released on CRAN. Install it with: install.packages("chronicler") {chronicler} allows you to create objects that carry a log with them. Here is an example of an object that has been created using {chronicler}, and saved using save...

2698 sym R (1801 sym/5 pcs) 4 img

Get packages that introduce unique syntax adopted less?

20.05.2022

I have this hypothesis that packages that introduce a unique syntax, or a workflow change, get adopted less by users, even if what these packages do is super useful. I’m going to discuss two examples of packages that I think are really, really useful, but sometimes I wonder how many R users use them, or would use them if they were aware these p...

6651 sym R (1099 sym/9 pcs) 4 img

Get packages that introduce unique syntax adopted less?

20.05.2022

I have this hypothesis that packages that introduce a unique syntax, or a workflow change, get adopted less by users, even if what these packages do is super useful. I’m going to discuss two examples of packages that I think are really, really useful, but sometimes I wonder how many R users use them, or would use them if they were aware these p...

6651 sym R (1099 sym/9 pcs) 4 img

Some learnings from functional programming you can use to write safer programs

25.05.2022

Learning number 1: make functions fail early When writing your own functions, avoid conversion of types without warning. For example, this function only works on characters: my_nchar <- function(x, result = 0){ if(x == ""){ result } else { result <- result + 1 split_x <- strsplit(x, split = "")[[1]] my_nchar(paste0(split_x[-1...

5309 sym R (2342 sym/22 pcs) 2 img

R will always be arcane to those who do not make a serious effort to learn it…

01.06.2022

R will always be arcane to those who do not make a serious effort to learn it. It is not meant to be intuitive and easy for casual users to just plunge into. It is far too complex and powerful for that. But the rewards are great for serious data analysts who put in the effort. — Berton Gunter R-help August 2007 I’ve posted this quote on twi...

5610 sym R (1298 sym/3 pcs) 4 img

What’s the fastest way to search and replace strings in a data frame?

22.07.2022

I’ve tweeted this: Just changed like 100 grepl calls to stringi::stri_detect and my pipeline now runs 4 times faster #RStats — Bruno Rodrigues (@brodriguesco) July 20, 2022 much discussed ensued. Some people were surprised, because in their experience, grepl() was faster than alternatives, especially if you set the perl parameter in grepl(...

3443 sym R (4641 sym/4 pcs) 4 img

Capture errors, warnings and messages

11.03.2022

In my last video I tried to add a feature to my {loud} package (more info here) and I succeeded. But in succeeding in realised that I would need to write a bit more code than what I expected. To make a long story short: it is possible to capture errors using purrr::safely(): library(purrr) safe_log <- safely(log) a <- safe_log("10") str(a) ## ...

3502 sym R (4420 sym/16 pcs) 4 img

Bootstrapping standard errors for difference-in-differences estimation with R

10.11.2015

I’m currently working on a paper (with my colleague Vincent Vergnat who is also a Phd candidate at BETA) where I want to estimate the causal impact of the birth of a child on hourly and daily wages as well as yearly worked hours. For this we are using non-parametric difference-in-differences (henceforth DiD) and thus have to bootstrap the stand...

2120 sym R (830 sym/7 pcs) 2 img

Unit testing with R

30.03.2016

I've been introduced to unit testing while working with colleagues on quite a big project for which we use Python. At first I was a bit skeptical about the need of writing unit tests, but now I must admit that I am seduced by the idea and by the huge time savings it allows. Naturally, I was wondering if the same could be achieved with R, and wa...

3951 sym R (727 sym/6 pcs)

Careful with tryCatch

30.03.2016

tryCatch is one of the functions that allows the users to handle errors in a simple way. With it, you can do things like: if(error), then(do this). Take the following example: sqrt("a") Error in sqrt("a") : non-numeric argument to mathematical function Now maybe you’d want something to happen when such an error happens. You can achieve that wit...

3116 sym R (2464 sym/13 pcs)