Writing a book with Quarto

in the spirit of learning in publicI wanted an excuse to dive into Quarto to learn more about publishing formats beyond simple PDF and HTML documents.

If you’re not familiar, quarto (quarto.org) is the successor to RMarkdown, a next-generation scientific publishing system that works natively with Python, R, and OJS. If you already have RMarkdown you probably don’t need to do this Anything Get it to render with Quarto. The wonderful thing about Quarto (and to a lesser extent, RMarkdown) is that you can write a single input document and render multiple types of output documents – HTML, PDF, Word docs, presentations (PowerPoint, Beamer, RevealJS), dashboards, websites, books, blogs, and more). And, with Quarto Live, you can embed WebAssembly-powered interactive code blocks for R and Python directly into a Quarto document (example here,

I demonstrate here how I turned one of my old course websites, made up of a bunch of RMarkdown documents, into a stunning e-book using Quarto. I also briefly mention Quarto Manuscripts and the Quarto Dashboard at the end.

You can read the book or download the PDF here https://bdsr.stephenturner.us/,

Biological Data Science with R

I started a series when I was faculty at UVA workshops In response to the growing demand for practical education in data science and bioinformatics, which was lacking in the traditional curriculum at the time. eventually i changed it to a graduate courseand later in A Duration Directed to faculty seeking careers in translation science. the course was a software carpentry Styled live coding hands-on course, mostly using R, covering data manipulation with dplyr, visualization with ggplot2, predictive modeling with Caret, text mining with tidytext, RNA-seq analysis with DESeq2, basic statistics, survival analysis, and other topics.

I created the course website using RMarkdown Websites – a feature that I don’t think ever gained much popularity, but I found incredibly useful. you put one _site.yml File the file in the root of your project, and you’ll get a small “Build Website” button in the RStudio build pane. Press that button and it will render all the RMarkdown documents in the project, and give you a website with the pages listed just as they are. _site.yml file. I took a lot of inspiration from Jenny Bryan’s old STAT545 course, and borrowed teaching ideas from other courses and blog posts on the Internet.

https%3A%2F%2Fsubstack post media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e02e128 b6d0 40bd b015
The old RMarkdown website interface in RStudio.

It actually worked quite well! My old workshop and course material website is still up stephenturner.github.io/workshops (screenshot below), and the code is open source on GitHub (github.com/stephenturner/workshops,

—Quarto has entered the chat—

Quarto appeared on my radar at the last rstudio::conf in 2022 (before becoming Posit::conf), where Posit announced a name change, Public Benefit Corp status, Shiny for Python, and, Quarto. I have gradually transitioned most of my technical writing from RMarkdown to Quarto. I’ve always been a big fan of article packageAnd now Quarto is starting to catch up journal article templates (I have written biorecap paper using a generic arXiv quarto template,

I have bookmarks of lots of great reference books R for data science, hands on programming with rAnd python for data analysisAll of which are written in the form of quarto books.

document (quarto.org/docs/books) seemed simple enough. Simply stick a bunch of qmd files into a directory and reference them in a _quarto.yml file. I wanted an excuse to explore the book writing experience with Quarto, so I grabbed all the source code from my old course website to try it out.

I wanted to write this as a short tutorial, but There’s no tutorial here, because I didn’t really have to do anything! All RMarkdown sources from my old website just workedI made some minor customizations to it _quarto.yml from my old _site.ymlI updated the verbiage slightly to reference the book Chapter instead of texts, and I updated some places to use cross references Instead of hard-coded hyperlinks. I followed it GitHub Pages Publishing Document To configure my gh-pages branch to serve content, which I then push to the main branch after running quarto publish gh-pagesAnd I stuck a custom subdomain on the repo so I can serve it here bdsr.stephenturner.us instead of default stephenturner.github.io/bdsrThis process took me about an hour, book website is live bdsr.stephenturner.usand publish order automatically creates both PDF And to ePub versions are available.

https%3A%2F%2Fsubstack post media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac08cc99 021d 48b3 b5d7
My old course website, transformed into a Quarto book, hosted on GitHub Pages. is available bdsr.stephenturner.us,

Biological Data Science with R

This book is based on course material I developed around 2015 and taught through 2018, so it’s starting to show its age. There are some dplyr functions that have been deprecated or removed that it uses gather() And spread() instead of tidyr pivot_*()And it’s using caret and related packages instead of tidymodels. and in the Predictive Modeling and Forecasting ChapterThere is a section on influenza-like illness forecasting that shows perfectly regular seasonal ILI patterns during 2019-2021, a counterfactual that co-instructor and co-author VP (Pete) Nagaraj and I published a paper Years later.

I recently wrote a short essay about learning in public,

learning in public

In that spirit, I wanted to share some resources related to the books and other quarto topics I’ve been reading.

quarto books The documentation is a well-organized place to find more information about publishing a book with Quarto, and you can find other great examples in galleryI also wanted to point out two relatively new Quarto output document types that are worth a look,

Mine Cetinkaya-Rundell, Professor of the Practice of Statistical Science at Duke University, gave a great talk about this quarto manuscripts At the r/Medicine conference earlier this year. The talk was very good. with quarto manuscripts You can write a narrative and include additional R/Python/etc notebooks with the manuscript, and present the output in multiple formats. see example hereAnd my point below.

I have used and recommend flexdashboard To create static or glitter-enabled dashboards using RMarkdown. When the Quarto first launched, dashboards were missing for at least a year. Quarto 1.4 was released earlier this year quarto dashboard Along with other new features. Watch the short video below from the post.



Leave a Comment