Articles by Econometrics and Free Software

Data frame columns as arguments to dplyr functions

July 17, 2016 | Econometrics and Free Software

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:
convertToKmh <- function(dataset, col_name){
  dataset$col_name <- dataset$speed * 1.609344
This example is obviously not very interesting (you don’t need a function for this), but ... [Read more...]

Careful with tryCatch

March 30, 2016 | Econometrics and Free Software

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:
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 | Econometrics and Free Software

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...]
1 7 8 9

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)