Any of the code can be extracted directly from the XML version of the book content (compressed). You can use XPath queries to access just the code you want, or any of the text, examples, figures, tables, etc. You can use this as a sample document. Similarly, you can use the functions xmlSource() and xmlSourceFunctions() to evaluate collections of code, e.g. a section, an example, a particular node.
You can use the CodeDepends package to run the code up to the point to create a particular variable.
To retrieve all the code in a particular (sub)section, you can use the fact that each section has a sectionID attribute given in the form chapterNumber.sectionNumber.sectionNumber....sectionNumber. For example, we can access section 8.3.2 in chapter 12 with
source(url("http://rxmlwebtech.org/Rscripts/getRCode.R")) doc = xmlParse("http://rxmlwebtech.org/allBook.xml") runSectionID("184.108.40.206", doc)