Posted by Doug
on July 24, 2009
Technology /
No Comments
I have been using R for a few weeks now, and now that I have a feel for how to get things done, I am starting to explore how to get those things done faster. On the suggestion of a friend, I picked up Data Manipulation with R by Phil Spector. Once you get the hang of R syntax, it is a great book to show you how to actually get things done; I am most of the way through it, and would highly recommend it.
One thing he introduces in chapter 9 tangentially is the “system.time” function; feed it a code block, and it will tell you the amount of real and system time elapsed. So, it is the perfect test bench for which of two methods runs faster; he uses it to show you how you get a 4x speedup using the built-in “colSum” function over “apply”. Using vectorization, a loop is just as fast as “apply”, however without vectorization, you get a 60x slowdown using element-by-element looping.
This points to the key to R-speed: don’t lie to R. Tell it everything, so that it can allocate memory efficiently, which is by far your slowest task. Take this example for applying “rbind” across a set of data frames. Previously, I had thought “functional programming”, and naturally went with “Reduce”. However, this book motivated me to find the “do.call” solution. Observe the results.
> df <- lapply( 1:1000, function(z) data.frame( runif(1000 )))
> system.time( a <- do.call( cbind, df ))
user system elapsed
0.54 0.01 0.59
> system.time( b <- Reduce( cbind, df ))
user system elapsed
40.16 0.80 42.61
That’s right, the “Reduce” method took 80x longer than the “do.call” method. I am going to change some of my code right now…
Posted by Doug
on July 18, 2009
Excursions /
1 Comment
I work in Acton, and I live in Cambridge. Given that the driving distance is about 20 miles, and the biking distance about 25, it was only a matter of time until I rode the route. This week I did it in both directions, although not on the same time. All I can say is, thank goodness for the minuteman bikeway.
Continue reading…
Posted by Doug
on July 12, 2009
City Streets /
1 Comment
Finally, a picture of my bike. Love it! The bag under the seat has my flat fix kit, keys etc. That’s a cable lock I have stuck on the handlebars.

I had everything below the frame replaced. See my last post.

Push on pedals A to rotate chain ring B, driving chain C, rotating rear cog D, and pushing wheel E forward.
Posted by Doug
on July 10, 2009
City Streets /
No Comments
This is actually very limited advice on bike repair. But first, the background.
Continue reading…
Posted by Doug
on July 05, 2009
Technology /
No Comments
On the theme I’m using (Big City), the wordpress default for showing counts next to categories looks awful. The lines break after the link, so it will say something like “Technology ::break:: (31)”. The solution I found was basically just to hack the code where it prints the count, and move that up. This stuff is hard-coded in wordress, and I couldn’t find a CSS solution to my problem (I do suck at CSS, but that’s another story).
Here are the changes as of WP 2.8.
In “general-template.php”, locate the lines that say
$after = ' ('.$arcresult->posts.')' . $afterafter;
and change them to
$text .= <...>
There are a number of such lines, so this will make them all consistent. I think I counted 4 such changes.
The other change to make is in “classes.php”. Break line 1336 (which looked something like this before I got to it)
$link .= $cat_name . "</a>";
So that it becomes
$link .= $cat_name;
$link .= "</a>";
Now move up this block between those two lines:
if ( isset($show_count) && $show_count )
$link .= ' (' . intval($category->count) . ')';
This will change your formatting slightly if you were using the feed code, and I don’t have a good answer for you on that.
Posted by Doug
on July 05, 2009
Excursions /
No Comments
July 4 was awesome, but I won’t recount it here. I just wanted to point out this very cool bike group out on the street. Disco ball bike crowd riding around at 2 am? Yes, that’s sweet.
Today I went riding out around Cambridge to improve my mental map of the place. My realization is that there are a few very old areas — Harvard, Kendal Square, Porter Square in Cambridge, Concord, Lexington, and of course Boston — with direct roads between them. The names of these roads are generally given by the larger place (at least locally), which explains the numerous Cambridge, Harvard, Concord, Lexington streets, although rarely in the place for which they’re named.
I also discovered the source of the Minuteman Bikeway. Although the maps show the starting point as Alewife Station, there is actually a pleasant extension from past Davis Square not marked there. (See also my previous post on my ride on the bikeway.)