Appendix B — Tools used to make this book
To set up the environment for replicating the code used in this book the R language is needed as well as R and Rstudio IDE environments. The following sections contain the directions for installing R and RStudio, how to set up a book with quarto and how to use GitHub as a version saver source.
B.1 RStudio installation
Download and install R and RStudio IDE
B.2 Info on how to setup this project in quarto
quarto is the new version of Rmarkdown, it can be used for making notes, presentations, websites, books and more.
In this project the book has been made in quarto and version saved on github.
B.2.1 GitHub useful commands
You can do the same using the command line. In RStudio create a new project on a new directory, add git, and select quarto book project
The automated process will create a _quarto.yml
file, the top of the file will look like this one:
project:
type: book
On terminal type: quarto preview
It creates a folder _book
B.2.1.1 Add Github later:
existing-github-last to connect with github create a github repo with the same name of your project then type
usethis::use_git()
It asks you to commit all files in the RStudio project. This pushes all files in R to a remote folder designed to head to the github repo.
In terminal connect with the github repo:
git init
git remote add origin
https://github.com/Fgazzelloni/infectious.git
git branch -M main
git push -u origin main
B.2.2 Publish your book on github pages
change the quarto.yml
file into:
project:
type: book
output-dir: docs
add a .nojekyll file, type in terminal:
touch .nojekyll
then type
quarto render
some issues might arise if more than one calculation is made inside a single chunks split the chunks!
quarto render creates a folder docs
B.3 Add a package
devtools::create("yourpkg")
Now that you have your book done, you might need to add some customized data to use within your analysis.
In order to do that, you’ll need to just add data in the way that is usually done when inside a package.
B.3.1 Building blocks of the package inside the quarto book
B.3.1.1 ADD DATA TO PACKAGE
set the data from the original source and tidy appropriately
usethis::use_data_raw()
it creates a .R script where to put the steps for get the data ready
once data are ready
usethis::use_data(yourdata)
It creates the R folder where the .R scripts of data documentation is located
usethis::use_r("yourdataset")
read how to document your work
vignette("rd-other") # for datasets
vignette("rd")
devtools::document()
devtools::load_all(".")
B.3.1.2 ADD PACKAGE INFO
so the ? (NAMESPACE) works
usethis::use_package_doc()
devtools::document()
B.3.1.3 ADD DATA PACKAGE INFO
usethis::use_r("yourdataset")
devtools::document()
when filling the data .R script for explaining what’s inside the dataset a specific structure needs to be used (see examples)
when new data are added
Build tab and —> More —> clean and install (this is not there anymore whae you start with devtools::create("yourpkg")
) to add the new data to NAMESPACE