Generator functions, or function factories as they're sometimes called, can be quite useful. I was writing a function recently where some data was being processed, but I wanted to give the user the option to process it further. There are standard, straight forward ways of doing this of course, but I had a nifty idea:… Continue reading Self-destructing function that generates self-destructing functions
Recursive interactive function
This one's a bit silly.
T-test for partially paired data
Simple example for creating a custom S3 class with methods
It can be really handy to create your own classes and methods in R. Most obviously it's very handy if you're creating a package for a particular procedure. Then you'd want a summary() method to quickly get some descriptive statistics, a plot() method to display results in a graphical manner, and so on.
But also outside of writing packages might a custom class and a few methods come in handy. Most frequently in my experience it's in the form of a print() method.
Creating an S3 class and methods can be really simple, while still make life (or at least coding) that little bit less cumbersome.
Stratified partitioning – uniform and normal test
I claimed in a previous post that my method of selecting the number of strata when performing stratified partitioning on a uniformly distributed continuous variable, gave the optimal result, as measured by between-fold variance. All well and good, you might think, but there's one big problem. The variable i partitioned wasn't merely uniformly distributed, it was distributed entirely regularly and evenly.
Stratified sampling/partitioning with continuous control variable
This is a suggestion for an approach to creating optimal strata of a continuous variable for further partitioning, followed by a visual justification for this assessment.
The partitioning itself is done with createFolds() from the caret package, but grouping, plotting and all the rest does not depend on any external library.
Append element to function body
I don't use append() very often, but when I do I'm a little annoyed when I rediscover that I can't reference elements by name, but have to do it by index only.
It's especially irksome as to add this feature all you'd have to do is include a couple of short and simple lines of code.
It's such a simple change that I figured I wouldn't even have to do it in an editor, I could do it all programmatically.
Find coordinates for line intersects (crossings)
A recent question on StackOverflow inspired me to develop a good method for finding the coordinates of intersection between two lines. As the method takes as input a discrete set of points and relies on interpolation (linear, cubic, or any other) to make a line, it's important to be aware of the assumptions being made.
Points, fills and lines
.Rprofile
.Rprofile is a wonderful thing, and a treacherous thing; it is one of the primary means of personalizing ones R development environment. And therein lies the paradox. Coding, whether it is short bash snippets, specialized R scrips or low-level software libraries, is an inherently social thing. While you might not be sharing everything, the thought… Continue reading .Rprofile





