Kriging with metR

Say you have data measured at different weather stations, which in Argentina might look something like this estaciones[data, on = c("nombre" = "station")] |> ggplot(aes(lon, lat)) + geom_point(aes(color = t)) + geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + scale_color_viridis_c() Because this is not a regular grid, it’s not possible to visualise this data with contours as is. Instead, it’s necessary to interpolate it into a regular grid.

Continue reading

One of the recurring debates in some spaces of the R community is about dependencies. After a few posts on Mastodon I wanted to capture my opinions on the subject to help me understand them better, and because long-form articles are much better to talk about contentious topics than short-burst posts. Dependencies are invitations for other people to collaborate with you Many thinkers have marvelled at the magic inside books.

Continue reading

For a while I wanted to write a post to compile some of the tricks I’ve learnt over the years of using rmarkdown. I also wanted other people’s input so I asked for suggestions on Mastodon. So here are the 11 tips I decided to include in no particular order. Make chunk options non-optional I use this trick to force myself to write captions to all figures: knit_plot <- knitr::knit_hooks$get("plot") knitr::knit_hooks$set(plot = function(x, options) { if (is.

Continue reading

An important part of a scientific project, such as a journal paper or a PhD thesis, is accessing datasets. To keep things reproducible datasets should be accessible, either provided in the repository itself or in a remote location. Also for reproducibility, it’s important to be able to check if the data you get is the same as the data you expect. I wanted to share my technique for downloading and accessing datasets that strives for maximum reproducibility and user-friendliness.

Continue reading

I started to use R full time for my research about 5 years ago when I started working on my Masters’ thesis and up until today there was one thing missing: proper contour labels. Now, thanks to the wonderful isoband package, I finally got what I wished for and it’s bundled in the latest release of metR. So let’s set up the stage for the problem. I have a 2D field that I want to visualise as a contour map.

Continue reading

For my PhD I’m currently writing a paper using rmarkdown. Since I care about reproducibility, I’m using renv to register the versions of the R packages I use and to manage a local library that doesn’t affect the rest of my system. With that, anyone who wants to reproduce my work could download all the code, run renv::restore() and have an R environment very similar to the one I use.

Continue reading

The stop() function allows you to terminate the execution of a function if there is a fatal problem. For example, imagine this code that calculates the square root of a number but only if the input number is positive. real_root <- function(x) { if (x < 0) { stop("'x' cannot be negative.") } sqrt(x) } real_root(2) ## [1] 1.414214 real_root(-2) ## Error in real_root(-2): 'x' cannot be negative. If x is negative, the function throws an error.

Continue reading

Author's picture

Elio Campitelli


Atmospheric sciences graduate researcher at CONICET

Argentina