Took a look at Ernie Chan's blog, but it doesn't have much detail. Yes, there is a cointegration package in R which can be gotten to programmatically, but I would use GRETL first.
Chan does reference the book, Alexander, Carol (2001). Market Models: A Guide to Financial Data Analysis. John Wiley & Sons.
I have this book, and have found it quite valuable. One of these days, I will buy some of her more recent works.