# Articles by Bruno Rodrigues

### My free book has a cover!

January 6, 2017 |

I’m currently writing a book as a hobby. It’s titled Functional programming and unit testing for data munging with R and you can get it for free here. You can also read it online for free on my webpage What’s the book about? Here’s the teaser... [Read more...]

### Functional programming and unit testing for data munging with R available on Leanpub

December 23, 2016 |

The book I’ve been working on these pasts months (you can read about it here, and read it for free here) is now available on Leanpub! You can grab a copy and read it on your ebook reader or on your computer, and what’s even better is that ... [Read more...]

### Work on lists of datasets instead of individual datasets by using functional programming

December 20, 2016 |

Analyzing a lot of datasets can be tedious. In my work, I often have to compute descriptive statistics, or plot some graphs for some variables for a lot of datasets. The variables in question have the same name accross the datasets but are measured for different years. As an example, ... [Read more...]

### I’ve started writing a ‘book’: Functional programming and unit testing for data munging with R

November 3, 2016 |

I have started writing a ‘book’ using the awesome bookdown package. In the book I explain and show why using functional programming and putting your functions in your own packages is the way to go when you want to clean, prepare and transform lar... [Read more...]

### Merge a list of datasets together

July 29, 2016 |

Last week I showed how to read a lot of datasets at once with R, and this week I’ll continue from there and show a very simple function that uses this list of read datasets and merges them all together. First we’ll use read_list() to read all ... [Read more...]

### Read a lot of datasets at once with R

July 25, 2016 |

I often have to read a lot of datasets at once using R. So I’ve wrote the following function to solve this issue:
read_list <- function(list_of_datasets, read_func){

read_and_assign <- function(dataset, read_func){
dataset_name <- as.name(dataset)
dataset_name <- read_func(dataset)
}

# invisible is used to suppress the unneeded output
output <- invisible(
sapply(list_of_datasets,
read_and_assign, read_func = read_func, simplify = FALSE, USE.NAMES = TRUE))

# Remove the extension at the end of the data set names
names_of_datasets <- c(unlist(strsplit(list_of_datasets, "[.]"))[c(T, F)])
names(output) <- names_of_datasets
return(output)
}
You need to supply a list of datasets as well as the function to read the datasets to read_list. So for example to read ... [Read more...]

### Data frame columns as arguments to dplyr functions

July 17, 2016 |

Suppose that you would like to create a function which does a series of computations on a data frame. You would like to pass a column as this function’s argument. Something like:
data(cars)

convertToKmh <- function(dataset, col_name){
dataset$col_name <- dataset$speed * 1.609344
return(dataset)
}
This example is obviously not very interesting (you don’t need a function for this), but ... [Read more...]

### Careful with tryCatch

June 20, 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 ... [Read more...]

### Unit testing with R

March 30, 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 ... [Read more...]

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

November 10, 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 ... [Read more...]

### Update to Introduction to programming econometrics with R

May 2, 2015 |

This semester I taught a course on applied econometrics with the R programming language. For this, I created a document that I gave to my students and shared online. This is the kind of document I would have liked to read when I first started using R. I already had ... [Read more...]

### Export R output to a file

February 21, 2015 |

Sometimes it is useful to export the output of a long-running R command. For example, you might want to run a time consuming regression just before leaving work on Friday night, but would like to get the output saved inside your Dropbox folder to take a look at the results ... [Read more...]

### Introduction to programming econometrics with R

January 11, 2015 |

This semester, I’ll be teaching an introduction to applied econometrics with R, so I’ve decided to write a very small book called “Introduction to programming Econometrics with R”. This is primarily intended for bachelor students and the focus is not much on econometric theory, but more on how ... [Read more...]

### R, R with Atlas, R with OpenBLAS and Revolution R Open: which is fastest?

November 10, 2014 |

In this short post, I benchmark different “versions” of R. I compare the execution speeds of R, R linked against OpenBLAS, R linked against ATLAS and Revolution R Open. Revolution R Open is a new open source version of R made by Revolution Analytics. It is linked against MKL and ... [Read more...]

### Object Oriented Programming with R: An example with a Cournot duopoly

April 23, 2014 |

I started reading Applied Computational Economics & Finance by Mario J. Miranda and Paul L. Fackler. It is a very interesting book that I recommend to every one of my colleagues. The only issue I have with this book, is that the programming language they use is Matlab, which is proprietary. ... [Read more...]

### Using R as a Computer Algebra System with Ryacas

December 31, 2013 |

R is used to perform statistical analysis and doesn't focus on symbolic maths. But it is sometimes useful to let the computer derive a function for you (and have the analytic expression of said derivative), but maybe you don't want to leave your comfy R shell. It is possible to ... [Read more...]

### Nonlinear Gmm with R – Example with a logistic regression

November 7, 2013 |

In this post, I will explain how you can use the R gmm package to estimate a non-linear model, and more specifically a logit model. For my research, I have to estimate Euler equations using the Generalized Method of Moments. I contacted Pierre Chaussé, the creator of the gmm library ... [Read more...]

### Method of Simulated Moments with R

January 29, 2013 |

Second update on my research, details here. [Read more...]

### Simulated Maximum Likelihood with R

January 16, 2013 |

First update on my research, details here. [Read more...]

### New website!

December 11, 2012 |

This is my new website! It’s built using jekyll-bootstrap and hosted on Github. [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)