Marketing Analytics
← All posts

New R-Only and Python-Only Chapter Examples

We've added two new sets of files for the Chestnut Ridge examples in the book: R-only scripts and Python-only scripts. The original examples split the work between R, which runs the analysis, and Tableau, which builds the charts and maps. The new scripts do the whole example in one language, from loading the data through the final charts and maps, so you can follow along without Tableau. They cover every chapter with a hands-on example: Chapters 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, and 17.

The original R and Tableau files are still available. If you're already using them in a course, nothing has changed for you.

Each chapter page in the Chapters section now organizes its downloads into four groups. Data Files holds the CSV datasets, which work with every version of the example. R and Tableau Files holds the original R scripts and Tableau workbooks. R Only Files holds the new standalone R scripts. Python Only Files holds the new standalone Python scripts. Each script walks through the example step by step, with comments explaining what each step does, and runs from top to bottom. The Python scripts are also split into cells, so you can run them one step at a time in VS Code, Spyder, or PyCharm.

Before you run your first example, we recommend running the setup script for your language. You'll find both under Getting Started: Software Setup at the top of the Chapters page. Run "00 - Install and Test R Packages.R" or "00 - Install and Test Python Packages.py" once, from top to bottom. It checks that your version of R (4.3 or later) or Python (3.10 or later) is recent enough and installs any packages the examples use that you don't already have. It then confirms that each package loads and draws a quick test plot to show that plotting works. The Python script also downloads the English stop words used in Chapter 17 and checks that the file-choosing dialog box used to open the data files works.

At the end, the setup script prints a report listing each package and whether it loaded. If everything says OK, you're ready to run the chapter examples. If a package fails, run the script again. If it still fails, restart R or Python and try one more time. The first run can take several minutes and needs an internet connection.

You can download files one chapter at a time from each chapter's page, or download everything at once from the buttons at the top of the Chapters page. There are three zip files: All R & Tableau Files, All R Only Files, and All Python Only Files. Each zip has a folder for every chapter that includes the chapter's data files, so you only need one download to run every example in that language. The R Only and Python Only zips also include the matching setup script.

The video walkthroughs currently cover the R and Tableau versions of the examples. Walkthroughs for the R-only and Python-only versions are on the way, and we'll post an update when they're available.