This is how we at Journalism++ Stockholm used R code to cover election night at Aftonbladet September 14th 2014.
getData.R and analyze.R contains all the interesting stuff.
Here is a blog post about the same topic: http://jplusplus.se/covering-election-night-with-r/
And here a summary of the output: https://storify.com/jensfinnas/valet-2014