Building a Book

Building a Book
Author

Matt Kavanaugh

Published

February 9, 2023

Prompt:

The goal of this week’s blog is to document what you are doing when things do not go according to plan.

Similar to previous exercises, we have a specific use case in mind: we want to build a book from a github repository.

What happens in practice usually, is that we run into some problems. So your real task turns into that of a bug-hunter and fixer. Luckily, you have a community (the class discussion board) who might be able to help you.

What we want: build a book

Build the html version of the 2nd edition for Hadley Wickham’s book Advanced R Programming from a github repository.

Steps:

  1. Clone the repository https://github.com/hadley/adv-r.
  2. Open the R project in the repository in RStudio.
  3. Activate the Build tab (by default in the top right panel). Click on the Build Book button.
  4. The book will be available in html format as index.html

Deliverable (1): what is the last word in chapter 15? - You don’t have to answer this question, if things don’t work.

  1. The last word in Chapter 15 is under the second question of the Exercises section, and is the word “class”.

What to do when things don’t work?

Errors happen, they are frustrating, but if we learn something from them, we can turn them into valuable experiences.

  • check the Questions and Answers forum in Canvas whether there is a solution available for your problem.

  • if the above document does (not yet) include your question, document the error you encounter (be as concise and specific as you can at the same time)

  • if the Question and Answers forum does (not yet) include a solution, describe one approach on how you tried to solve the problem (and how this did not work).

  • submit the description of your problem in Canvas at Discussions > Questions and Answers. Write the paragraph in the mindset that you want to get help from somebody, and you try to describe the problem you are encountering.

  • Extra points (1 pt for the first suggested working solution): post a solution to one of the problems in the Questions and Answers forum (your own does not count!).

Deliverable (2): Write a paragraph on the biggest problem you encountered when you were building the book, (and how you managed to solve it.)

When building the book, the biggest issue I came across was discovering that I needed to install so many additional packages and files in order for the book to compile. I discovered that the version of “tinytex” installed was out of date, and I needed to install the one which was compatible with my current version of R. I consulted Sudesh’s solution on the discussion forum, when he suggested to try uninstalling and installing tinytex using the “tinytex::(un)install_tidytex()” function. Also, other packages such as “zeallot” were not installed, and I had to search for each of these packages and install them as new errors occurred. I was able to search for the necessary packages and install them using the “install.packages()” command.
Additionally, I had to replace a couple of functions that were no longer operational in current versions of R. For instance, the knitr package was particularly difficult to work with, as the wrap command which was being used by the common.R file ceased to exist as of the version released last summer. I consulted the discussion board for help, and surely enough, there was a suggested answer to my problem provided by Yichuan. Then, I investigated the linked Github repository for more information. As it turns out, I initially went in to replace the “wrap” command with “sew”, as had been suggested on our discussion board as well as on the Common.R Github page. However, as it turned out, an error persisted when attempting to compile the common.R file. Lines 56-61 of that file featured code that would display an error message in the event that the “wrap” command malfunctioned. However, I had replaced each “wrap” with “sew” throughout those lines, and this file would not compile until I changed the error code commands back to “wrap”. It took a good bit of playing around to figure that one out, and I ended up doing so by running a few lines of code at a time throughout the enitre script until I figured out where things were going wrong. Eventually, I narrowed it down to the lines mentioned above, and I was able to fix the problem. Overall, it was a rewarding experience to encounter issues and become stronger at debugging code as well as being able to consult the help of others when it became necessary.

You can write your experience directly into the README.Rmd file. Just make sure that you change the yaml at the top: change the author at the top, and give your post a new title (don’t change the category :))

Commit and push to your repo and you are done!