Day 32 - Website

Spring 2023

Smith College

Overview

Timeline

  • Why Bother with a Website?
  • Making a Website
  • Hosting a Website

Goal

Give you the tools to create a publishable website if desired.

Why Bother with a Website?

Websites for Packages

A website can act as a central repository for info about your package.


It will show all of the help files and vignettes you’ve worked hard to create, as well as other information.


It also gives your package a presence you can like to in your portfolios and say “I made this” (which is good).

But I have a GitHub Repo …

GitHub scares people.


Think back to the start of the semester, would you have dig around a GitHub repo to learn about a package?


If you want your package to be used widely, you need to make information about it accessible.

Perks of Real Websites

A dedicated website also conveys some other perks:

  • Hyperlink between your help pages and vignettes
  • Include graphics, diagrams, and plots
  • Host other content from outside your package
  • Host guidelines for contributing
  • Links to contact authors

ggplot2 includes a gallery of all the extension packages, for example.

Making a Website

Easier than You Think

Creating a website for a package isn’t all that complicated.


Much like many other package features, helpers have been created to do the heavy lifting.


If you have formatted things correctly thus far, many features of the website will be populated automatically.

To create the framework of a pkgdown site:

usethis::use_pkgdown()


To create all of the pages:

pkgdown::build_site()


That’s it!

What it Makes

Homepage

The README.md file from the base directory of your package will become your home page. You may not have made one yet. You can edit _pkgdown.yml for options.

Help reference

A page will be created to list all of your functions, with links to a separate page for each of them. Pages will link to each other if you linked to other functions in your help pages.

Vignettes

All of your vignettes will be readable on the site, complete with all of your code examples and visuals. If you have multiple, you can navigate between them from the top menu.

Website Files are in ./docs/

When you build your website, all the associated files will be saved to the ./docs/ directory.


If you have some web development experience, you may be tempted to tinker with some of the files.


I would advise against it, as many of them are regenerated whenever you run pkgdown::build_site(), and may undo your work.

R Project Name
.
├── R/
│   └── func1.R
├── man/
│   └── func1.Rd
├── inst/
│   ├── data/
│   │   └── example_data1.csv
│   └── other
├── vignettes/
│   └── v1.rmd
├── docs/
│   └── v1.html
├── tests/
│   └── testthat/
│       └── test-func1.R
├── NAMESPACE
├── DESCRIPTION
├── LICENSE
├── NEWS.md
├── README.Rmd 
├── .gitignore
└── .Rbuildignore

Hosting a Website

What is “Hosting”?

Websites on the internet need to be hosted by some service. The service holds the files people see, the server that people connect to, and coordinate the traffic so all that is possible.


You either need to do this yourself by owning a server, or you need to pay someone else to do it.


Or (at least for now) we can get GitHub to do it for free using GitHub pages (what our course site runs on).

How GitHub Pages Work

With GitHub pages you can host static .html files for free from your project repo.


This does mean you can’t have anything like an R Shiny app, but a static page can get you pretty far.


You can a designate a specific folder in your repo, or a specific branch to be the one turned into a website (gh-pages branch by default).

NOTICE! - You Can’t Host Private Repos




You cannot host a repo that is private (like your project repos). You will thus have to copy your code into a new public repo. This will be needed if you want to publish your package anyway.


You do not need to host the website for the standard, just render it locally (or rather make sure I can do so).

Setting up GitHub Pages

You will need to set up an access token on github. You can use usethis::create_github_token(). Copy the key from the resulting page and use gitcreds::gitcreds_set() to register the token with your computer.


After you have a token set up, you can use usethis::use_pkgdown_github_pages() to set up GitHub pages hosting.


Now, every time you push your website will be re-rendered.

For Next Time

Topic

Lab 9

To-Do