Exporting Clock Entries from org-mode to CSV

If you’ve used the clocking features of org-mode, you’re no doubt familiar with the clock table, which allows you to summarise time spent on different tasks. This is great for getting an overview of projects, but it’s not a very flexible tool if you want to have a more detailed idea of how you spend your time.

At this point I’ve accumulated about a year’s worth of clocked work time in org, and while clock tables have served me well so far, eventually I just wanted to get my data into R or Python for more minute analysis, and charts like the following:

Calendar heatmap example

However, I haven’t come across a reliable1 way to get individual clock entries out of org-mode files and into a more widely readable format. So I’ve written one.

The org-clock-csv package, available on GitHub and through MELPA, parses all of the clock entries in an org-mode file and exports them to CSV format. At present the columns include start and end dates, the task’s category, effort, and tags. Habits are also given a flag.

You can invoke the parser by calling org-clock-csv in interactive mode, in which case it will parse whatever you’ve got in org-agenda-files and pop up a buffer with the results. The function can also be called from lisp code with a file argument, and there’s an org-clock-csv-batch version that will dump the CSV results to standard output (for use with Emacs in batch mode).

If you’re looking for inspiration on what to do with your shiny new data set, here’s a recent post (though it’s not org-mode based) that poses some good questions.

  1. I did find the in-progress R package orgclockr, but its home-grown org parser (in R) failed on my files. Since the best org parser is already avaiable in Emacs, it made more sense to me to write an Emacs package that outputs a universal format.

comments powered by Disqus