The Working R Programmer
https://mailund.github.io/rprogrammerblog/
Recent content on The Working R Programmer
Hugo  gohugo.io
Copyright © 2018  Thomas Mailund
Fri, 02 Mar 2018 00:00:00 +0000

About
https://mailund.github.io/rprogrammerblog/about/
Fri, 02 Mar 2018 00:00:00 +0000
https://mailund.github.io/rprogrammerblog/about/
Hi, I’m Thomas Mailund, and on this blog, I write about R programming. I have a more generalpurpose blog on www.mailund.dk, but since I got fed up with jumping through hoops to get R code and output displayed the way I want it, I have moved all R topics here, where I can use knitr and Markdown + Pandoc to create posts.

More Linked List Performance
https://mailund.github.io/rprogrammerblog/2018/10/19/morelinkedlistperformance/
Fri, 19 Oct 2018 16:35:54 +0200
https://mailund.github.io/rprogrammerblog/2018/10/19/morelinkedlistperformance/
I’m still working on improving the speed of my pattern matching DSL. I have improved the speed of constructors and pattern matching, so now I wanted to get back to comparing vectors and linked lists.

The Cost of Pattern Matching
https://mailund.github.io/rprogrammerblog/2018/10/18/thecostofpatternmatching/
Thu, 18 Oct 2018 16:38:41 +0200
https://mailund.github.io/rprogrammerblog/2018/10/18/thecostofpatternmatching/
Following up on my previous post, where I figured out to improve the speed of constructors, I will have a look at pattern matching in this post.
I haven’t added any of this to pmatch yet.

The Cost of Constructors
https://mailund.github.io/rprogrammerblog/2018/10/16/thecostofconstructors/
Tue, 16 Oct 2018 18:09:55 +0200
https://mailund.github.io/rprogrammerblog/2018/10/16/thecostofconstructors/
So, err, I wanted to compare the performance of linked lists versus R vectors on a case where the former is expected to perform better than the second: building a sequence one element at a time.

Thunks and Trampolines
https://mailund.github.io/rprogrammerblog/2018/10/10/thunksandtrampolines/
Wed, 10 Oct 2018 15:38:25 +0200
https://mailund.github.io/rprogrammerblog/2018/10/10/thunksandtrampolines/
Have you ever written a recursive function that you couldn’t use because you ran out of stack space when you applied it to large data sizes? Then thunks and trampolines might be for you.

Lazy queues
https://mailund.github.io/rprogrammerblog/2018/10/04/lazyqueues/
Thu, 04 Oct 2018 09:13:01 +0200
https://mailund.github.io/rprogrammerblog/2018/10/04/lazyqueues/
The purpose of the lazy lists I implemented in my previous post was to build lazy queues. Lazy lists give you constant time concatenation, which can be useful in itself, but I needed it to implement persistent functional queues.

Lazy lists
https://mailund.github.io/rprogrammerblog/2018/10/03/lazylists/
Wed, 03 Oct 2018 09:13:01 +0200
https://mailund.github.io/rprogrammerblog/2018/10/03/lazylists/
I wanted to write about lazy lists and lazy queues today, but I spent most of the day struggling with getting lazy evaluation to work. Finally, I convinced myself that something was broken in R, and I was justified in thinking that; upgrading to the most recent version resolved the issue.

Promises, their environments, and how we evaluate them
https://mailund.github.io/rprogrammerblog/2018/10/02/promisestheirenvironmentsandhowweevaluatethem/
Tue, 02 Oct 2018 09:13:01 +0200
https://mailund.github.io/rprogrammerblog/2018/10/02/promisestheirenvironmentsandhowweevaluatethem/
Have you ever wondered how functions are evaluated? How you can have arguments that would raise errors, but do not, or how default arguments can be expressions that depend on function arguments that you haven’t seen yet when you define a function?

Lists and functional queues
https://mailund.github.io/rprogrammerblog/2018/10/01/listsandfunctionalqueues/
Mon, 01 Oct 2018 07:13:01 +0200
https://mailund.github.io/rprogrammerblog/2018/10/01/listsandfunctionalqueues/
I wanted to write something about function parameters, how these are passed as socalled “promises”, how these have associated scopes (and the consequences of that), and how they give us lazy evaluation.

Environments and formulae
https://mailund.github.io/rprogrammerblog/2018/09/27/environmentsandformulae/
Thu, 27 Sep 2018 04:41:19 +0200
https://mailund.github.io/rprogrammerblog/2018/09/27/environmentsandformulae/
In my two previous posts on nonstandard evaluation, Scoping rules and NSE and Overscoping and eval, I explained:
How R finds the bindings of variables by looking through chains of environments.

Overscoping and eval
https://mailund.github.io/rprogrammerblog/2018/09/22/overscopingandeval/
Sat, 22 Sep 2018 12:23:09 +0200
https://mailund.github.io/rprogrammerblog/2018/09/22/overscopingandeval/
In my previous post I used the lm function for an example of scope rules, but I left a few details out. I didn’t want to muddy the example with too many details, so I chose to lie a little.

Scoping Rules and NSE
https://mailund.github.io/rprogrammerblog/2018/09/20/scopingrulesandnse/
Thu, 20 Sep 2018 05:00:15 +0200
https://mailund.github.io/rprogrammerblog/2018/09/20/scopingrulesandnse/
Earlier this week, I wrote some tweets about how you have to be careful about scopes when you do “nonstandard evaluation”. I cover this in both Metaprogramming in R and DomainSpecific Languages in R, but this tweet

New Package Releases: foolbox and tailr
https://mailund.github.io/rprogrammerblog/2018/04/27/newpackagereleasesfoolboxandtailr/
Fri, 27 Apr 2018 00:00:00 +0000
https://mailund.github.io/rprogrammerblog/2018/04/27/newpackagereleasesfoolboxandtailr/
I have just released version 0.1.0 of foolbox and version 0.1.2 of tailr. I haven’t actually done much on the packages the last three weeks, and they have been very close to these releases for a while, but now I had the spare time and energy to actually send them off.

“Optional” types using pmatch
https://mailund.github.io/rprogrammerblog/2018/03/30/optionaltypesusingpmatch/
Fri, 30 Mar 2018 00:00:00 +0000
https://mailund.github.io/rprogrammerblog/2018/03/30/optionaltypesusingpmatch/
Some programming languages, e.g. Swift, have special “optional” types. These are types the represent elements that either contain a value of some other type or contain nothing at all. It is a way of computing with the possibility that some operations cannot be done and then propagating that along in the computations.

Lots of Function Transformations
https://mailund.github.io/rprogrammerblog/2018/03/27/transformingfunctionswithcasescalls/
Tue, 27 Mar 2018 19:34:39 +0200
https://mailund.github.io/rprogrammerblog/2018/03/27/transformingfunctionswithcasescalls/
The last couple of days I’ve been doing a lot of experimenting with a package for function rewriting: foolbox. I am doing some function transformations in both pmatch and tailr and they look very much alike, so I figured I should collect the shared functionality in a separate package.

pmatch 0.1.3
https://mailund.github.io/rprogrammerblog/2018/03/22/pmatch013/
Thu, 22 Mar 2018 00:00:00 +0000
https://mailund.github.io/rprogrammerblog/2018/03/22/pmatch013/
I have just released version 0.1.3 of pmatch to CRAN. There are not a lot of changes to this version compared to 0.1.2, but enough that I felt it would be good to get a version out before I pull the entire package apart to make it dependent on toolbox for its transformation function.

Transforming functions with cases calls
https://mailund.github.io/rprogrammerblog/2018/03/18/transformingfunctionswithcasescalls/
Sun, 18 Mar 2018 00:00:00 +0000
https://mailund.github.io/rprogrammerblog/2018/03/18/transformingfunctionswithcasescalls/
The issue with bytecompilation I wrote about yesterday can indeed be fixed by transforming functions that call cases. And that was very easy to implement since I already had all the bits and pieces I needed for it from the tailr transformations.

Building a package that uses pattern matching
https://mailund.github.io/rprogrammerblog/2018/03/17/buildingapackagethatusespatternmatching/
Sat, 17 Mar 2018 14:35:16 +0100
https://mailund.github.io/rprogrammerblog/2018/03/17/buildingapackagethatusespatternmatching/
After a week spend programming string algorithms in C—for teaching purposes, I am not working on a new readmapper—it is nice to get back to programming in R. I made a new release of tailr today, so that is good, but what I really wanted to work on was matchbox.

tailr v0.1.1
https://mailund.github.io/rprogrammerblog/2018/03/17/tailrv0.1.1/
Sat, 17 Mar 2018 12:35:16 +0100
https://mailund.github.io/rprogrammerblog/2018/03/17/tailrv0.1.1/
As I wrote about here and here, I had a problem in tailr with higherorder functions. In the transformation for tailrecursion optimisation, I need to know which actual functions each name refer to, in order to apply userdefined transformations, but with higherorder functions, those are not known until runtime.

Redblack trees in matchbox
https://mailund.github.io/rprogrammerblog/2018/03/12/redblacktreesinmatchbox/
Mon, 12 Mar 2018 00:00:00 +0000
https://mailund.github.io/rprogrammerblog/2018/03/12/redblacktreesinmatchbox/
I’m working on implementing redblack search trees in matchbox and have managed most of it by now. I still need to implement deletion and the rebalancing code for handling those, but I have insertion up and running.

Linked lists in matchbox
https://mailund.github.io/rprogrammerblog/2018/03/11/linkedlistsinmatchbox/
Sun, 11 Mar 2018 00:00:00 +0000
https://mailund.github.io/rprogrammerblog/2018/03/11/linkedlistsinmatchbox/
I have started playing with data structures in matchbox and the first structure I implement had to be linked lists. That is the most versatile data structure I use and it is missing from R.

Problems With Higher Order Functions in tailr
https://mailund.github.io/rprogrammerblog/2018/03/09/problemswithhigherorderfunctionsintailr/
Fri, 09 Mar 2018 18:38:52 +0100
https://mailund.github.io/rprogrammerblog/2018/03/09/problemswithhigherorderfunctionsintailr/
Ok, there is a problem with higherorder functions in my tailr package that I ran into while writing linked list functions for my matchbox package.1
If you write a tailrecursive function that uses a parameterfunction, the tailr package will complain that it doesn’t see that function in scope.

Matchbox and CMD CHECK
https://mailund.github.io/rprogrammerblog/2018/03/08/matchboxandcmdcheck/
Thu, 08 Mar 2018 06:59:09 +0100
https://mailund.github.io/rprogrammerblog/2018/03/08/matchboxandcmdcheck/
Ok, first, the package I wrote about yesterday will be called matchbox, following Dmytro Perepolkin’s suggestion (thanks!). You can get it at GitHub.
There isn’t much to it yet since I haven’t really started implementing the data structures I want to put in it.

Help Me Choose a Package Name
https://mailund.github.io/rprogrammerblog/2018/03/07/helpmechooseaname/
Wed, 07 Mar 2018 07:07:11 +0100
https://mailund.github.io/rprogrammerblog/2018/03/07/helpmechooseaname/
What’s in a name? That which we call a rose By any other word would smell as sweet — William Shakespeare, Romeo and Juliet
I have plans for reimplementing several of the data structures I wrote about in Functional Data Structures in R.

Variable bindings with pattern matching
https://mailund.github.io/rprogrammerblog/2018/03/06/variablebindingswithpatternmatching/
Tue, 06 Mar 2018 00:00:00 +0000
https://mailund.github.io/rprogrammerblog/2018/03/06/variablebindingswithpatternmatching/
I just added a new feature to my pmatch package. You will need the development version to get it, until I make a new release, and I have a few more features planned before that.

Another approach to evaluating dynprog expressions
https://mailund.github.io/rprogrammerblog/2018/03/05/anotherapproachtoevaluatingdynprogexpressions/
Mon, 05 Mar 2018 00:00:00 +0000
https://mailund.github.io/rprogrammerblog/2018/03/05/anotherapproachtoevaluatingdynprogexpressions/
In the approach to evaluating dynamicprogramming expressions, that I wrote about yesterday, I used ranges and recursionspecifications to build a loop for updating a table and then evaluated that loop inside an environment where local variables would overscope the quosure environment from the specifications.

Comments
https://mailund.github.io/rprogrammerblog/2018/03/04/comments/
Sun, 04 Mar 2018 00:00:00 +0000
https://mailund.github.io/rprogrammerblog/2018/03/04/comments/
Ok, if this is working, it should now be possible to comment on posts here.
I was a bit slow in trying this out, because I had a hellish time setting up the blog in the first place, and I expected adding comments support with Disqus would be just as hard, but if this is working, it was a simple matter of adding

Evaluating dynprog expressions
https://mailund.github.io/rprogrammerblog/2018/03/04/evaluatingdynprogexpressions/
Sun, 04 Mar 2018 00:00:00 +0000
https://mailund.github.io/rprogrammerblog/2018/03/04/evaluatingdynprogexpressions/
I think I now have a complete implementation of the dynamic programming DSL I wrote about the other day. You can install it from the GitHub repository if you want to experiment with it.

Tickmarks for log10 axis
https://mailund.github.io/rprogrammerblog/2018/03/03/tickmarksforlog10axis/
Sat, 03 Mar 2018 18:00:00 +0100
https://mailund.github.io/rprogrammerblog/2018/03/03/tickmarksforlog10axis/
For the tailr post I needed to plot some benchmark results. I still haven’t figure out how I can get plots from RMarkdown automatically moved to the right directory here, but that’s okay.

Designing a DSL for dynamic programming
https://mailund.github.io/rprogrammerblog/2018/03/03/designingadslfordynamicprogramming/
Sat, 03 Mar 2018 10:00:00 +0100
https://mailund.github.io/rprogrammerblog/2018/03/03/designingadslfordynamicprogramming/
I’m working on an example for one of the chapters of Domain Specific Languages in R that will appear in the printed version but weren’t included in the earlier ebook. The plan is to have one to three extra example chapters, depending on how much I can do before my deadline on April 1st.

tailr — Tail Recursion Optimisation
https://mailund.github.io/rprogrammerblog/2018/03/02/tailrtailrecursionoptimisation/
Fri, 02 Mar 2018 10:38:06 +0100
https://mailund.github.io/rprogrammerblog/2018/03/02/tailrtailrecursionoptimisation/
Believe it or not, all the bother with setting up this blog was such that I could write this post easier than I could on Wordpress. So now, let us get to some actual R programming!

Blog Setup
https://mailund.github.io/rprogrammerblog/2018/03/02/blogsetup/
Fri, 02 Mar 2018 09:48:01 +0100
https://mailund.github.io/rprogrammerblog/2018/03/02/blogsetup/
Ok, I hadn’t planned to write any more about how the blog is set up, since that isn’t that interesting to me and probably isn’t to you — either you know a lot more about this than me, in which case I have nothing to teach you, or you just don’t care, which I can relate to.

Purpose of this blog
https://mailund.github.io/rprogrammerblog/2018/03/02/purposeofthisblog/
Fri, 02 Mar 2018 07:58:24 +0100
https://mailund.github.io/rprogrammerblog/2018/03/02/purposeofthisblog/
Since I already have a blog, you might be asking, “why another one?”.
It’s a fair question, and I am not creating a new blog just to make you follow two instead of one.

First Post
https://mailund.github.io/rprogrammerblog/2018/03/01/firstpost/
Thu, 01 Mar 2018 22:46:35 +0100
https://mailund.github.io/rprogrammerblog/2018/03/01/firstpost/
This is my first attempt at a Hugo+Blogdown blog. I got tired of struggling with formatting R code on my Wordpress blog, so figured it would make sense to use RMarkdown to write about R code.

https://mailund.github.io/rprogrammerblog/1/01/01/
Mon, 01 Jan 0001 00:00:00 +0000
https://mailund.github.io/rprogrammerblog/1/01/01/
“Optional” types using pmatch /*! jQuery v1.11.3  (c) 2005, 2015 jQuery Foundation, Inc.  jquery.org/license */ !function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?

https://mailund.github.io/rprogrammerblog/1/01/01/
Mon, 01 Jan 0001 00:00:00 +0000
https://mailund.github.io/rprogrammerblog/1/01/01/
Thunks and Trampolines /*! jQuery v1.11.3  (c) 2005, 2015 jQuery Foundation, Inc.  jquery.org/license */ !function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){var c=[],d=c.