As user dvt mentioned, this is built using bookdown[1], an R library (with the help of Pandoc). You can see that the example chapter of this book looks exactly like the bookdown output[2]. The bookdown PDF explains in detail how to use Rmd+RStudio+R+Pandoc+Markdown to publish this.
I might do one of the trade-offs between self-publishing and working with a publisher. With Kindle Direct Publishing, it's pretty straight forward. It's more about the tooling to produce the text and the process of using Kindle Direct.