What’s R vector, Victor?

Cook with flatmap

In this week’s episode of the “Hidden Monads in R” series, I’ll explore the vector aspect of R data structures, and see how the flatmap operation can be quite useful.

[Read more]

Let’s talk about NA-s!

The knights who say NA

ARTHUR: Well, what is it you want?
HEAD KNIGHT: We want… a paste function that can deal with NA-s!

A language for statistical computing clearly needs to be able to deal with missing values, and R has various ways to do so. I will briefly go through some of them, then propose an interesting way to spice it up a bit.

[Read more]

Monads everywhR

A monad is a very useful pattern. If you don’t know what it is, then read my post from a few years ago, watch this excellent video, and you can also read J. Carroll’s insightful post. Once you think you get the concept, this blog post will be much more enjoyable. That’s because I’d like to focus on why monads don’t seem to want to spread in the R language.

After all, R is a functional programming language, and it would be natural for monads to be part of the basic toolkit, like in Haskell or Rust, yet this isn’t the case. There have been and are attempts: for example the {chronicler} or the {maybe} package, and perhaps more. But I’ve never seen anyone use them in production, at least not in my field, bioinformatics. In this post, I’d like to think through why this is the case.

[Read more]

SAEM PAKEJ, DIFFRINT VERSHUNZ: PAWSIBL?

Concerned cat

It started as a simple exchange on Mastodon. Apparently, what is natural for my nix-infused brain may seem far-fetched for non-nixers. Multiple versions of the same package must be possible. But I actually tried this only once, so I decided to document it.

[Read more]

She issued install.packages() – you won’t believe what happened next!

Just install.packages(), he said.
It’s easy, he said.
(Unknown R tutor)

CRAN has spoiled us. Most of the time, it’s a breeze to add new packages to our environment. Just issue the command, and the package becomes available. If you’re an RStudio user, you can simply start typing the package name select it from a list and it’s done. This is because R and CRAN work together to handle your package’s R dependencies: other packages that are needed for the functioning of the package you actually want to use.

[Read more]

Maybe monad in R

A monad is mysterious entity from the ivory towers of category theory, an idea that turned out to be quite useful in programming. Part of the myth surrounding monads is that as soon as you understand them, you lose the ability to explain the concept. Since I’m not a mathematician, not even a trained programmer, I won’t even try to explain anything. Instead, I just implement a simple monad.

R, being a functional programming language should be able to benefit from this concept. The goal is not to create a library, just to demonstrate monads, and gain a practical understanding of its usefulness.

[Read more]