As pointed out by a recent read the R source post on the R hub’s website, reading the actual code, not just the documentation is a great way to learn more about programming and implementation details. But there is one more activity to get even more hands-on experience and understanding of the code in practice. In this post, we provide tips on how to interactively debug R code step-by-step and investigate the values of objects in the middle of function execution.
In this post in the R:case4base series we will examine sorting (ordering) data in base R. We will learn to sort our data based on one or multiple columns, with ascending or descending order and as always look at alternatives to base R, namely the tidyverse’s dplyr and data.table to show how we can achieve the same results. It is recommended to first have a look at the post on subsetting to understand the concepts underlying the sorting process in more detail.
In this post in the R:case4base series we will look at string manipulation with base R, and provide an overview of a wide range of functions for our string working needs. We will use simple examples to learn to perform basic string operations, concatenate strings, work with substrings, switch cases, quote, find and replace within strings and more. Some interesting bonuses will also be included. As always, some popular alternatives to base R will also be suggested and many useful references provided for further reading.
In this post in the R:case4base series we will look at one of the most common operations on multiple data frames - merge, also known as JOIN in SQL terms. We will learn how to do the 4 basic types of join - inner, left, right and full join with base R and show how to perform the same with tidyverse’s dplyr and data.table’s methods. A quick benchmark will also be included.
Inspired by a recent post on how to import a directory of csv files at once using purrr and readr by Garrick, in this post we will try achieving the same using base R with no extra packages, and with data·table, another very popular package and as an added bonus, we will play a bit with benchmarking to see which of the methods is the fastest, including the tidyverse approach in the benchmark.
We all know that feeling. We have this great idea about a new project, feature, function, piece of code. What do we want? Write that amazing new code! When do we want it? Right NOW! The aim of this post is to try and give you at 3 good reasons to resist that urge and consider other options, be it in your business projects or your private projects.
In this summertime post in the case4base series, we will look at useful tools in base R, which let us profile our code without any extra packages needed to be installed. We will cover simple and easy to use speed profiling, more complex profiling of performance and memory and, as always, look at alternatives to base R as well, with a special shout out to profiling integration in RStudio.
In the previous articles of the R:case4base series we discussed and learned how to reshape data with base R to a form that is practical for our use and how to subset data to get the relevant parts of it with base R. In this one, we will look at aggregation techniques using base R’s stats::aggregate generic function, focusing on the method for data frames. This will allow us to easily and safely create simple aggregations, but also provide a framework for completely custom aggregation functionality defined as separate functions that can be properly documented and unit tested.
How to use this article Selecting (subsetting) relevant data from a data.frame Constructing meaningful subsets simply and safely More ways to provide subset indices Alternatives to base R TL;DR - Just want the code Exercises References Exercise answers In the previous article we discussed and learned how to reshape data with base R to a form that is practical for our use. In this one, we will look at basic data manipulation techniques, namely obtaining relevant subsets of our data.
How to use this article Basic wide to long reshape Basic long to wide reshape Advanced reshape Alternatives to base R TL;DR - Just want the code Exercises References Exercise answers Discuss the article This is the first post in the R:case4base series. The aim of the series is to elaborate on very useful features of base R that are lesser known and many times substituted with custom functionality of external packages.