Pages (Desktop)

Pages (Mobile)

Loops in R: Nested loops

Programming loops are a way to repeat blocks of code to perform the same task over and over again. R offers the same functionality to perform repetitive tasks, allowing to write less and more efficient code.

This guide follows on from my introduction to loops guide, and shows you have to use nested loops in R. A nested loop is a loop within a loop.


BES Masterclass: Using R for mapping and spatial analysis

Today I presented at the British Ecological Society Palaeoecology Group "Masterclass in R" seminar series on using R for mapping and spatial analysis.

If you couldn't make the presentation and would like to see what I spoke about, as well as access the full R code, read more for details!


Fixing the default plot window on Linux for high DPI displays

Running R on Linux with a high-DPI display and finding that the default plot window is too small and looks terrible?

Click read more to find out how to fix it!


Introduction to loops in R

Programming loops are a way to repeat blocks of code to perform the same task over and over again. R offers the same functionality to perform repetitive tasks, allowing to write less and more efficient code.

This guide introduces you to loops in R, explains how to write them, including for loops and while loops, and some best practice for writing efficient loops. I'll also take a look at vectorization in R, explaining what it is and why you should used vectorized functions where possible. This guide will introduce you to the basics of programming and automating tasks in R.


Getting started with R

Ever wanted to try R, but wasn't sure where to start? Or perhaps you are unsure of what R is and what it can do?

New for 2021, I have completely rewritten, revised and greatly expanded my introduction to R guide. Additionally, I have added additional guides for importing data into R, and to give an overview of R graphics and creating plots (see below).

The introduction guide is now much more comprehensive, and includes everything you need to get started with R! Check them out:

Part 1: Introduction to R An introduction to R - what is R, where to get R, how to get started using R, a look at objects and functions, an overview of data structures, and getting started with manipulating data.
Part 2: Importing data into R This guide shows you how to import your existing data into R from .csv or Excel files.
Part 3: An overview of graphics in R This guide gives you an overview of some of the graphical capabilities of base R to produce high quality plots.


Getting started with R: Importing data into R

In the second part of this expanded guide series introducing you to R, this guide shows you how to import data into R from csv files and Excel spreadsheets.

Of course, R can import many other data types, but these two are very common and will get you started!


Getting started with R: An overview of graphics in R

In the final part of this expanded guide series introducing you to R, this guide gives you an overview of the graphics systems in R, and gets you started creating plots using base graphics.


Updates

Hello! you may have noticed a lack of updates to the blog in the last two years. This was in part due to me buying a house and spending a long time renovating it (and the garden), which took up most of my spare time. Since that is now *mostly* complete (it is never complete), I am able to spend some time updating the blog again.

Since i first started the blog, I have become more experienced in using R and use it in many more different ways compared to how I first started. I also now try and write more efficient R code, usually in the form of functions, than what i did previously. Looking back at some of my guides, much of the code is "inefficient", but it is accessible to beginners. As part of updates, I intend to revisit several of my guides and update them with new code and new explanations. However, the goal of the blog is to always make the code accessible to everyone, and that will not change.

I've also made a few changes to the site to tweak the design slightly. These changes are quite minor so you may not notice them, but they should "tidy up" some of the design. If you notice any errors, please let me know!

Additionally, the guides on the blog now have a new "information" panel. Here's an example:

Title My uber guide
Author Benjamin Bell
Published Today
Last updated
R version 4.1.1
Packages base

This will replace the information boxes that previously showed on each guide, and keep all the useful details in one place.

There are definitely some new guides coming soon (really this time), and to start, why don't you check out the completely rewritten and updated guide to using different line types in R?


Bathymetric maps in R: Getting and plotting data

Bathymetric maps are topographic maps of water bodies (oceans, seas, lakes, rivers), equivalent to Digital Elevation Models (DEMs), except for submerged terrain.

Useful in their own right, bathymetric maps can also improve the look of maps created using DEMs, giving depth to water features.

This 2-part guide shows you how to create bathymetric maps in R using freely available data from online sources, how to import and plot this in R. Part 2 explores using different colour schemes/palettes for really effective maps. Read on for more!




Bathymetric maps in R: Colour palettes and break points

Part 2 of the guide for making bathymetric maps in R. This part focuses on creating effective colour schemes using break points to control the colour.