A Quarto website that shows SAS users how to write their analyses in R with the segue package. Each page in comparisons/ puts SAS code next to the R code, and reports how closely the results agree.
The R code runs when the site is built, so you need R with segue installed:
pak::pak("posit-dev/segue")
install.packages(
c("cli", "covr", "downlit", "gt", "haven", "knitr", "modeldata",
"pkgsite", "remotes", "rmarkdown", "scales", "segue", "tidyverse", "xml2")
)Then, from this folder:
quarto renderOr preview with live reload:
quarto previewLocally, results are cached in _freeze/ (freeze: auto), so a page re-runs only when its source changes. _freeze/ is not committed: the GitHub Actions workflow in .github/workflows/quarto-site.yaml runs all the code on each push to main and publishes the site to the gh-pages branch.
The pages in reference/ are written by pkgsite from segue's .Rd help files. Don't edit them by hand. The GitHub Actions workflow rebuilds them from the latest segue on every publish, so you only need to rebuild them locally to preview changes.
install.packages("pkgsite")Then, from this folder:
Rscript _pkgsite/build.RThe script clones posit-dev/segue into _packages/segue (or pulls it if it is already there), deletes reference/, and writes a fresh .qmd file for each exported function plus reference/index.qmd. To build from a local checkout of segue instead, pass its path:
Rscript _pkgsite/build.R ../segueThen render the site. The examples in each page run during the render, so segue must be installed.
To do the same thing by hand in R, from this folder:
pkgsite::write_reference(
pkg = "../segue", # path to the segue package source
quarto_file_path = ".", # read the pkgsite settings from this _quarto.yml
examples = TRUE # run the examples when the page renders
)build.R also tidies the descriptions in reference/index.qmd so they can be styled; without that step the index still works but looks plainer.
What controls the output:
| Setting | Where |
|---|---|
Page layout, source link, and the hidden library(segue) that the examples need |
_pkgsite/_reference.qmd |
| Index page title and layout | _pkgsite/_index.qmd |
| Sections and order in the index | pkgsite > reference > index > contents in _quarto.yml |
| Sidebar on the reference pages | website > sidebar (id: reference) in _quarto.yml |
When segue gains a new exported function, add its .qmd file to a section under contents and to the reference sidebar. Functions marked @keywords internal are skipped.
testing.qmd shows segue's test coverage, overall and per file, with a covr report for each line. The numbers are computed here, not read from Codecov. You need covr 4.0.0 or later.
Then, from this folder, pass a branch, tag, or commit SHA of posit-dev/segue (the default is main):
Rscript _coverage/build.R
Rscript _coverage/build.R v0.1.0
Rscript _coverage/build.R 4c9dddd
Rscript _coverage/build.R --local ../segue # a local working treeThe script exports that commit from _packages/segue into a temporary folder (so the checkout used by _pkgsite/build.R doesn't change), installs segue's dependencies, and runs covr::package_coverage(). It writes:
| Output | Contents |
|---|---|
data/coverage.rds |
The covr object, the ref and SHA, versions, and a per-file summary |
assets/coverage-badge.svg |
Badge for the whole package |
assets/coverage/<file>.svg |
One badge per file in segue's R/ folder, e.g. assets/coverage/sas_round.svg |
Then render testing.qmd again. A badge can be used on any page, e.g.  on a comparison page.
After each render, _post-render.R runs downlit on the new HTML files. It turns R function names in code blocks and inline code, such as sas_round(), into links:
- segue functions link to this site's
reference/pages, with paths relative to each page, so the links work on Posit Connect and in a local preview. - Functions from other packages link to their published documentation, for example
round()to rdrr.io andhaven::read_sas()to the haven site. Finding those links requires an internet connection during rendering. - SAS code is not changed.
- Links to segue functions that have no reference page, such as
exact_binom_test_sas()(marked@keywords internal), are removed, and the text is kept.
Quarto runs the script for you because of post-render in _quarto.yml. It needs downlit (install.packages("downlit")); without it, the script prints a message, and the site is left without links. To add the links to an existing _site folder by hand, from this folder:
Rscript _post-render.RWhen Quarto lists no new files, the script processes every HTML file in _site.
| Path | What it does |
|---|---|
_syntax/sas.xml |
SAS syntax highlighting, from PSIAIMS/CAMIS (MIT, Michael Walshe) |
segue.theme |
Code colors |
_filters/translation.lua |
Builds the side-by-side SAS and R panes |
comparisons/_rows.ejs |
Template for the comparison lists |
_post-render.R |
Adds downlit links to the rendered pages |
_pkgsite/ |
Templates and build script for the reference pages |
_coverage/build.R |
Computes segue's test coverage and badges |
R/setup.R |
Plot theme and table helpers used by every page |
styles.scss |
Site theme |