When things run slower than we’d like in R we tend to reach for another, usually compiled, language, and move our code there. What if it “just happened”? What started out as a silly exploration of how to count digits ended up with a race to see which language does it fastest. Maybe some surprises here for some, maybe some bad implementations on my part - let’s find out.| Irregularly Scheduled Programming
How well do you know your fundamental operators in different languages? ‘Easy’ examples help to fortify that knowledge, and comparing across languages makes for some neat implementation detail discoveries.| Irregularly Scheduled Programming
In which I confront the way I read code in different languages, and end up wishing that R had a feature that it doesn’t.| Irregularly Scheduled Programming
Python seems to be everywhere these days, and I’m really into learning languages, so it should come as no surprise that I’m learning a lot of Python. This post serves as a review of Pandas Workout as well as a ‘first impression’ review of the Pandas approach to data.| Irregularly Scheduled Programming
I keep saying that the more programming languages you know, the more you will understand all the others you know - I’m now at the point where I want to solve every problem I see in a handful of different languages. They all offer different functionality, and some are certainly more suited to particular problems than others, but there’s a world of difference between two characters and importing from two libraries.| Irregularly Scheduled Programming
Continuing my theme of learning all the languages, I took the opportunity of a programming puzzle to try out the same approach in a handful of different languages to compare how they work. For an upcoming APL’ers meetup the challenge was set as posed at the end of in this post, namely Maxxie and Minnie The maxxie of a number n is the largest number you can achieve by swapping two of its digits (in decimal) (or choosing not to swap if it is already the largest possible). The minnie is the sm...| Irregularly Scheduled Programming
In this post I describe a useful programming pattern that I implemented, and hopefully provide a gentle introduction to the idea of monads. The motivation for all of this was that I had a {dplyr} pipeline as part of a {shiny} app that queries a database and I wanted to “record” what steps were in that pipeline so that I could offer them as a way to ‘reproduce’ the query. Some of the steps might be user-defined via the UI, so it was a little more complicated than just a hardcoded query...| Irregularly Scheduled Programming
As October rolls around once more, the term Hacktoberfest might pop across your feeds; an effort aiming to encourage people to contribute to open-source software, particularly if they’re new to that. In this post I’ll describe what I’m offering towards that goal. Hacktoberfest has been running since (I think) 2017 and I’ve participated in at least one year - previously contributors who had the requisite 4 PRs merged received a free t-shirt, but I suspect that program became overly cos...| Irregularly Scheduled Programming
In this post I explore some differences between R, python, julia, and APL in terms of mutability, and try to make something that probably shouldn’t exist. I watched this code_report video which describes a leetcode problem; You are given an integer array nums, an integer k, and an integer multiplier. You need to perform k operations on nums. In each operation: Find the minimum value x in nums. If there are multiple occurrences of the minimum value, select the one that appears first. Replace...| Irregularly Scheduled Programming
Gleam vs R I thoroughly dislike ‘hot takes’ comparing programming languages based solely on a “feel” or differential familiarity (“I know this one better therefore it is better) so when I came across a blog post detailing a small learning project written in Gleam I wanted to understand what advantages and disadvantages that language brings to the problem. This post details a side-by-side comparison after rewriting the project in R with a goal of better understanding the approach on ...| Irregularly Scheduled Programming
At a recent APL-focussed Meetup someone posed a challenge to slice up the components of an IPv4 address with an APL language and it prompted me to learn a bit more about how that works in general and how I could do the processing in APL myself. The person who posed the challenge had approached it themselves using J which I’m only vaguely familiar with, but it gave me an opportunity to learn a bit more about it. It’s not all that dissimilar from the Dyalog APL I know a bit better; it uses ...| Irregularly Scheduled Programming
A while ago (2019 seems so long ago now) I started working on something I thought was interesting but which never really got any traction. It has potential once more, so it’s about time I wrote up what it does and why I think it’s a useful idea. I’m going to talk about using the {dplyr} package on some data with rows and columns, but we’re not talking about data.frames or tibbles… Okay, I probably do need to talk about them a little to start with. I’m also taking this opportunity ...| Irregularly Scheduled Programming
I’ve been using a lot of programming languages recently and they all have their quirks, differentiating features, and unique qualities, but one thing most of them have is that they handle strings as a collection of characters. R doesn’t, it has a “character” type which is 0 or more characters, and that’s what we call a “string”, but what if it did have iterable strings? For comparison, here’s some Python code for i in "string": print(i) s t r i n g and some Haskell upperA = ma...| Irregularly Scheduled Programming
A while ago I made some plots I really liked, but I never made a blog post about them. Then the data source stopped working and I couldn’t make them again. Now there’s a new data source, so it’s time for a post about some weather data! Way back in the mid 2010s I was interested in getting my hands on some weather data to answer a question I had. In Australia we have the Bureau of Meteorology (“don’t call it ‘the bom’”) which has been keeping track of weather data for a very lo...| Irregularly Scheduled Programming
I heard that learning Elm is a good way to approach learning Haskell, so I gave it a go and was surprised early on about an approach to writing abstracted HTML. In this post I compare the way that R and Elm generate HTML and the differences between their approaches. I was listening to the Linux Dev Time podcast based on a recommendation and this episode (episode 100) was about “how many different programming languages should you learn?” One suggestion in amongst the interesting discussion...| Irregularly Scheduled Programming
Another day, another short riddle to be solved with several programming languages! This one is nice because solving it doesn’t need a lot of code, but it uses some interesting aspects of evaluation. I saw this post which isn’t new (it’s from 2022) that poses a nice problem to solve: With the numbers 123456789, make them add up to 100. They must stay in the same order but you can use addition, subtraction, multiplication, division, brackets etc. All numbers must be used exactly once. and...| Irregularly Scheduled Programming
I saw a toot celebrating a short, clean implementation of a square root finding algorithm and wanted to dig a bit deeper into how it works, with a diversion into some APL. This was the toot from Jim Gardner Doubly pleased with myself. Been doing the Tour of Go. Got to the section where you make a square root function, which should return once the calculated value stops changing. Struggled for ages. Trimmed and trimmed. Until finally… this! The calculation for z was given, and I don’t unde...| Irregularly Scheduled Programming
With a serious yak shaving deviation, I have a really short “cheat” solution to one of the featured Exercism problems. It’s been a really insightful journey getting to this point, and as always I’ve learned a lot along the way. The fact that I was able to understand the required changes and propose them is thanks to the open-source nature of programming languages. This all started out innocently enough - I’ve been using Exercism.org to get a feel for a lot of other programming langu...| Irregularly Scheduled Programming
I’ve tried to get this same image transformation working at least three times now, but I can finally celebrate that it’s working! I’ve been (re-)learning Julia and I still love the language, so it was time to take my learning to the next level and actually build a package. I’ve tried to get this same image transformation working at least three times now, but I can finally celebrate that it’s working! I’ve been (re-)learning Julia and I still love the language, so it was time to ta...| Irregularly Scheduled Programming
Hyperlinks are great - they add value to a block of text by adding additional links out to more things to read - but they’re a distraction if you’re trying to read an in-depth piece of text and comprehend it linearly. Let’s hack the web! Hyperlinks are great - they add value to a block of text by adding additional links out to more things to read - but they’re a distraction if you’re trying to read an in-depth piece of text and comprehend it linearly. Let’s hack the web! I’ve be...| Irregularly Scheduled Programming
I’m solving Advent of Code this year using a relaxed criteria compared to last year in that I’m allowing myself to use packages where they’re helpful, rather than strictly base R. Last year I re-solved half of the exercises using Rust which helped me learn a lot about Rust. This year I’m enamored with APL, and I wanted to share a particularly beautiful solution. ⚠⚠⚠⚠⚠ Spoilers ahead for Day 7, in case you haven’t yet completed it yourself. ⚠⚠⚠⚠⚠ I solved Day 7 of...| Irregularly Scheduled Programming
In the lead up to Christmas each year, Advent of Code offers a series of 25 puzzles which start out reasonably simple, but get progressively harder, eventually requiring knowledge of algorithms and dynamic programming techniques. Last year I solved these in (strictly) base R on the day they were released (or as close to as I could). I then (starting Dec 27) went back and re-solved (13 of) them in Rust. This post details what I learned along the way and some fun visualisations I made. As I eve...| Irregularly Scheduled Programming
Print debugging has its place. Sure, it’s not always the best way to debug something, but it can often be the fastest. In this post I describe a useful way to do this in Rust and how we can get similar behaviour in R. I love the Rust dbg! macro - it wraps a value or expression and prints the result to help debug what’s happening in the middle of some function. If we had some complicated function that combined some values, e.g. fn f(val1: i32, val2: i32) -> i32 { // do some things let othe...| Irregularly Scheduled Programming
If you’re reading this hoping that I’m done with droning on about array-languages, close the tab… it only gets worse from here. If you thought APL was unreadable, even after my earlier blog posts, again - close button is right there. In this post I try out a brand new stack-based array language and continue to advocate for learning such things. I subscribe to a lot of RSS feeds these days - it’s certainly making a comeback, and it’s great to see developers returning to blogging outs...| Irregularly Scheduled Programming
I’m part of a local Functional Programming Meetup group which hosts talks, but also coordinates social meetings where we discuss all sorts of FP-related topics including Haskell and other languages. We’ve started running challenges where we all solve a given problem in a language of our choosing then discuss over drinks how they compare. This month we went with an “easy” problem with a wrinkle - we would solve the ‘strain’ exercise from Exercism (Haskell, Python - your access to t...| Irregularly Scheduled Programming
I keep hearing the assertion that “writing APL/Haskell/etc… makes you think differently” and I kept wondering why I agreed with the statement but at the same time didn’t think too much of it. I believe I’ve figured out that it’s because I happened to have been using Array-aware languages this whole time! It turns out R is an even better language for beginners than I thought. Let’s start with some basics. A “scalar” value is just a number by itself. That might have some units...| Irregularly Scheduled Programming
One thing that has really caught my attention as I learn more programming languages is the idea of generators or infinite sequences of values. Yes, infinite. Coming from R, that seems unlikely, but in at least several other languages, it’s entirely possible thanks to iterators and lazy evaluation. I saw this video which solves a codewars challenge using an infinite list, which references this one on the same topic. First, a diversion into recursion A timely combination. @rverbsr In Haskell,...| Irregularly Scheduled Programming
I’ve been learning at least one new programming language per month through Exercism and the #12in23 challenge. I’ve keep saying, every time you learn a new language, you learn something about all the others you know. Plus, once you know \(N\) languages, the \(N+1^{\rm th}\) is significantly easier. This post covers a calculation I came across in Haskell, and how I can now do the same in a lot of other languages - and perhaps can’t as easily in others. All of the languages here, I’m le...| Irregularly Scheduled Programming
Your collaborator says to you “I have some code I’d like to distribute to people who will probably work in R most of the time. I don’t write R, but I write C. Can you package this up for me?” so you have a few options: re-write the code in R, package up the C code and make it available in R, or say no. I decided to try out the second of these, and this post details how I achieved that. Before we even start, this is an excellent post summarising many of the finer points involved here -...| Irregularly Scheduled Programming
With Functional Programming, we write functions which take arguments and do something with or based on those arguments. You might not think there’s much to learn about given that tiny description of “an argument to a function” but the syntax and mechanics of different languages is actually widely variable and intricate. Let’s say I have some function in R that takes three arguments, x, y, and z, and just prints them out in a string in that order. r_fun <- function(x, y, z) { sprintf("...| Irregularly Scheduled Programming
--- Update: this post was discussed late March 2024 on HackerNews and lobste.rs. --- I’ve been learning at least one new programming language a month through Exercism which has been really fun and interesting. I frequently say that “every language you learn teaches you something about all the others you know” and with nearly a dozen under my belt so far I’m starting to worry about the combinatorics of that statement. APL isn’t on the list of languages but I’ve seen it in codegolf ...| Irregularly Scheduled Programming
I’ve been following the drama of the RustConf Keynote Fiasco (RKNF, per @fasterthanlime) from a great distance - I’m not involved in that community beyond starting to learn the language. But the controversial topic itself Compile-Time Reflection seemed like something interesting I could learn something about. A good start is usually a Wikipedia page, and I found one called “Reflective programming” under the “MetaProgramming” category, where it defines reflection is the ability of ...| Irregularly Scheduled Programming
This might not have been difficult for a seasoned web-dev, but it was reasonably tricky to find a clear solution online (at least it was for me) so here’s how I added the neat domain hints next to all the hyperlinks on my blog. This might not have been difficult for a seasoned web-dev, but it was reasonably tricky to find a clear solution online (at least it was for me) so here’s how I added the neat domain hints next to all the hyperlinks on my blog. I’m familiar with these from the RW...| Irregularly Scheduled Programming
Plotly has a nice way of making click-events available to the calling language, but it doesn’t quite work simply when using subplot(). This isn’t a post about a new feature, but I didn’t quickly find a resource for it so I’ll add my findings to make it easier for the next person. Plotly (as a graphics library) is a JavaScript library that has been ported to R, Python, Julia, and - surprising to me - MATLAB and F#. It provides an interactive plotting framework that works really nicely ...| Irregularly Scheduled Programming
I’ve been working my way through Exercism exercises in a variety of languages because I strongly believe every language you learn something about teaches you about all the others you know, and makes for useful comparisons between what features they offer. I was1 Learning Me a Haskell for Great Good (there’s a guide/book by that name) and something about Pattern Matching just seemed extremely familiar. Pattern Matching is sort of like a case statement, but rather than just comparing litera...| Irregularly Scheduled Programming
I’ve just finished reading ‘Version Zero’ by David Yoon. I really enjoyed it. There’s some (javascript) code on some separator pages between some of the chapters that is loosely tied into the plot and general theme of the book. I love solving puzzles, so what was I supposed to do, just leave it at that? Incidentally, I’ve hooked my reading list into my mini blog so my ‘Currently Reading’ list is (ideally) up to date. I can’t help myself when it comes to puzzles or easter eggs ...| Irregularly Scheduled Programming
Don’t show me puzzles, unless you want to be responsible for me staying up too late solving them. I’m far too easily nerd-sniped. This one was certainly the most complex I’ve ever solved. Quite complicated too, but definitely the most complex (you’ll see). A few days ago a colleague of mine pointed me to this FiveThirtyEight article, which isn’t new (2018), but does feature someone else we both work with as the author of the first puzzle. Brandon is a mathematician-turned-computatio...| Irregularly Scheduled Programming
I’ve had the impression lately that everyone is learning Rust and there’s plenty of great material out there to make that easier. {gifski} is perhaps the most well-known example of an R package wrapping a Rust Cargo crate. I don’t really know any system language particularly well, so I figured I’d wade into it and see what it’s like. The big advantages I’ve heard are that it’s more modern than C++, is “safe” (in the sense that you can’t compile something that tries to read...| Irregularly Scheduled Programming
Updated: 2022-09-04 I took a very long time to post about the last Australian Signals Directorate (then DSD) decryption, so this time I’ll be a lot more punctual. This article was published today announcing that ASD have collaborated to release a new 50c coin containing a decryption challenge. The new ASD 50c coin That looks like fun! Typing in the letters and numbers from the image certainly wasn’t, but after that. Of course, I’ll be solving the entire thing with R. Apparently there’...| Irregularly Scheduled Programming
Another ‘small learning project’ for me as I continue to learn Julia. I’ve said many times that small projects with a defined goal are one of the best ways to learn, at least for me. This one was inspired by yet another Reddit post These are at least reminiscent of Lissajous curves but they primarily just looked pretty cool - that animation is very nicely put together. That graphic was made using Typescript which is itself neat to begin with, but it looked like something that Julia migh...| Irregularly Scheduled Programming
I’ve long been interested in exactly how R works - not quite enough for me to learn all the internals, but I was surprised that I could not find a clear guide towards exactly how vectorization works at the deepest level. Let’s say we want to add two vectors which we’ve defined as x and y x <- c(2, 4, 6) y <- c(1, 3, 2) One way to do this (the verbose, elementwise way) would be to add each pair of elements c(x[1] + y[1], x[2] + y[2], x[3] + y[3]) ## [1] 3 7 8 but if you are familiar with...| Irregularly Scheduled Programming
I occasionally like a round of code-golf (e.g. recently) and I try to solve these with R, but this one gave me some hope that I could make use of a really cool feature I knew about in common lisp. lisp is timeless. https://xkcd.com/297 I have occasionally tinkered with lisp - initially because I learned emacs, but later because it’s really interesting and does teach a lot about quoting. Practical Common Lisp is a book I’m still (slowly) making my way through, but it’s a great read so f...| Irregularly Scheduled Programming
I occasionally like to participate in an odd sport known as ‘code golf’ where the aim is to write some code to achieve a given task using the smallest number of characters. The tradtional way to cheat at golf is to lower your score R isn’t optimised for this in the slightest (why would it be?) and there are other languages which have expanded character sets which are, e.g. BQL, MATL, and 05AB1E. These are typically short, contained problems which can be solved in a variety of ways, so ...| Irregularly Scheduled Programming
I just finished ‘Code: The Hidden Language of Computer Hardware and Software’ by Charles Petzold which was a really well-written (in my opinion) guided journey from flashing a light in morse code through to building a whole computer, and everything needed along the way. The section on encoding instructions for the processor (built up from logic gates) - assembly instructions as a human readable version of the machine code - was particularly interesting to me, and as I was describing this ...| Irregularly Scheduled Programming
I saw this post on Reddit’s r/dataisbeautiful showing this plot of streaming services market share, comparing 2020 to 2021 US Streaming Services Market Share, 2020 vs 2021 and thought it looked like a good candidate for trying out some plot improvement techniques. Yes, that was a reasonably long while ago, this post has taken quite some time to put together. Life. I’ve played with adding images to plot axes several times (also here, here, here) so that part shouldn’t pose too much of a ...| Irregularly Scheduled Programming
You may have seen the memes going around about fun ways to program the straightforward function isEven() which returns TRUE if the input is even, and FALSE otherwise. I had a play with this and it turned into enough for a blog post, and a nice walk through some features of R. The ‘traditional’ way to check if an integer is even is to check if it is divisible by 2. This can be achieved with the modulo operator %% which gives the remainder after dividing by another number. For example, 5 mo...| Irregularly Scheduled Programming
As soon as the R-Foundation posted that they’re inviting cleanup of old bugs, I knew it would be an opportunity to learn more about the way R works on the inside. I started looking through the list of open bugs for somewhere I could help out. I barely know anything about the actual C internals of the language (I’m hoping to learn) so I figured it would be best to start with some parts of the code I’m familiar with. I had an open bug report for the internals of glm which I extended with ...| Irregularly Scheduled Programming
I’ve written afewtimes about using an image as an x-axis label, and the solutions have been slowly improving. This one blows all of them out of the water. Claus Wilke (@ClausWilke) now has a {ggtext} package which can very neatly add images as x-axis labels! This makes the solution as simple as library(ggplot2) library(ggtext) library(rvest) ## GDP per capita, top 11 countries url <- "https://en.wikipedia.org/wiki/List_of_countries_by_GDP_(nominal)_per_capita" html <- xml2::read_html(url) g...| Irregularly Scheduled Programming
This journey started almost exactly a year ago, but it’s finally been sufficiently worked through and merged! Yay, I’ve officially contributed to the tidyverse (minor as it may be). I’m at least as useful as Zoidberg It began with a tweet, recalling a surprise I encountered that day during some routine data processing Source of today's mild heart-attack: I have categories W, X_Y, and Z in some data. Intending to keep only the second two: data %>% filter(g %in% c(“X Y”, “Z”) Did ...| Irregularly Scheduled Programming
This is the last update to this strange saga… I hope. Image labels… Photo: http://www.premierpaper.com/shop/custom-labels/ Easily two of the most popular posts on my blog are this one and this one describing a couple of ways in which I managed to hack together using an image as a category label in a ggplot. There are likely many people who believe one should never do such a thing, but given the popularity, it seems a lot of people aren’t listening to that. Good on you. via GIPHY One of ...| Irregularly Scheduled Programming