rghcard draws cards for a GitHub profile: the contributions card, with the contributions, commits and streaks of a user, and the statistics card, with the stars, page views, clones, release downloads and GitHub Actions runs of their repositories; and four cards that take a closer look, at their activity, their visitors, their GitHub Actions runs and their code. This article starts from made-up statistics, so that everything in it runs without a token, and ends with the cards on your own profile. Draw the cards in R goes through drawing them on your computer, step by step. The contributions card, The statistics card and More cards explain each number and chart of each card, and the options that change them.
Install and load the package
install.packages("rghcard", repos = c(
"https://sedzinfo.r-universe.dev",
"https://cloud.r-project.org"
))The cards
example_stats() returns the statistics of a made-up
user, example-user, with eight repositories, 30 days of
traffic and contributions since March 2019:
stats <- example_stats()
stats
#> GitHub statistics of example-user, collected until 2026-12-03
#> 8 repositories, 101 stars, traffic from 2026-11-03 to 2026-12-02, 4,132 contributions since 2019-03-14
#> Tables: repos (8 rows), views (240 rows), clones (240 rows), traffic (8 rows), referrers (12 rows), pages (9 rows), releases (4 rows), actions (87 rows), languages (15 rows), stars (101 rows), profile (1 rows), contributions (2822 rows), commits (69 rows), contribution_types (8 rows)contributions_card() draws their contributions, as an
SVG or a PNG file:
contributions_card(stats, "contributions.svg")Its key figures are the contributions since joining GitHub and in the last 12 months, the commits, and the current and the longest streak of days with contributions. Under them are the contributions per month and the languages by commits and by repositories. The contributions card explains each of them.
stats_card() draws the statistics of their
repositories:
stats_card(stats, "stats.svg")Its key figures are the repositories and their stars, the page views and clones of the last 30 days, the downloads of release files and the GitHub Actions runs. Under them are the page views and clones per day, with the busiest day labelled, and the most viewed repositories. The statistics card explains each of them, and how to choose other charts and another period.
In an SVG shown in a web page, as here, each column and bar tells its
value when you point at it. view_card() shows a card that
way in the Viewer pane of RStudio or Positron, and as a picture in the
Plots pane:
Four more cards take a closer look, each with its own key figures and charts:
-
activity_card(): the pull requests, issues, reviews and new repositories of the user, their followers, their contributions by type and by day of the week, and the repositories they commit to most. -
visitors_card(): the unique visitors and cloners of their repositories in the last 14 days, the sites that sent them and the pages they viewed. -
actions_card(): their GitHub Actions runs, how many succeeded and failed, how long they took and the busiest workflows. -
code_card(): the size of their code in each language, their largest repositories, their stars month by month, and their forks and watchers.
activity_card(stats, "activity.svg")More cards shows the four and explains each of their numbers and charts. Any card can also show the charts of any other.
Dark or light
theme = "light" draws a card in the colours of GitHub’s
light mode:
contributions_card(stats, "contributions-light.svg", theme = "light")On a GitHub profile, a <picture> element shows
each reader the card of their mode (see On your GitHub profile).
Your own statistics
collect_stats() reads the statistics of the repositories
you own and your contributions, and adds them to a history of CSV files,
in rghcard-data/ by default:
stats <- collect_stats()
contributions_card(stats, "rghcard-contributions.svg")
stats_card(stats, "rghcard-stats.svg")GitHub shows the page views and clones of a repository only to those
who can push to it, so collect_stats() reads them with a
token of yours, which the gh package finds in the
GITHUB_PAT environment variable or in the git credential
store; Draw the cards in R shows
how to put one there. A fine-grained token needs the permission
Administration: Read-only, a classic one the repo
scope. A fine-grained token, though, leaves out your private
contributions, which your profile may show as bare numbers:
contributions_token reads them with another token, such as
a classic one. The rghcard action reads them with the token of its
workflow, which sees your profile as others see it.
GitHub keeps the traffic for 14 days, so run
collect_stats() at least once a week: each run adds the new
days to the history, and the card can then cover more than 14 days.
read_stats() reads the history again, without asking
GitHub:
stats <- read_stats("rghcard-data")The history has a table for each kind of statistic, each a CSV file:
repos (stars, forks, watchers, open issues, size, language
and last push of each repository on each day of collection),
views and clones (per repository and day),
traffic, referrers and pages (the
totals, the referring sites and the most viewed pages of the 14 days
that GitHub gives, on each day of collection), releases
(downloads of each release file), actions (one row per
run), languages (the bytes of code of each repository in
each language), stars (the time of each star),
profile (the followers, and the users followed, on each day
of collection), contributions (per day since joining
GitHub), commits (per repository and year) and
contribution_types (per year and type). The help page of
collect_stats() describes each. Each collection reads the
contributions, the commits and their types whole, from GitHub’s GraphQL
API, which answers any token but none without one.
Private repositories and forks are left out, since the cards and
their history are usually public; include_private = TRUE
and include_forks = TRUE bring them in.
For another user, collect_stats() collects the public
statistics only: repositories, stars, forks, languages, release
downloads, GitHub Actions runs and contributions. Their statistics card
then shows other figures and charts, which The statistics card shows,
and Cards from a user name draws the cards
of any user from their user name, in R or in a Shiny app.
# dir = NULL keeps nothing on disk
octocat <- collect_stats(user = "octocat", dir = NULL)
contributions_card(octocat, "octocat-contributions.svg")
stats_card(octocat, "octocat-stats.svg")On your GitHub profile
GitHub shows on your profile the README of the repository named after
your user name. A GitHub Actions workflow in that repository can refresh
the cards every week: it runs rghcard’s GitHub Action, which installs R
and rghcard on GitHub’s machine, so it needs no R on your computer.
use_rghcard_action() writes the workflow into a copy of the
repository on your computer, and lists the next steps:
use_rghcard_action("path/to/your/profile/repository")Create a fine-grained token with this link, which fills in GitHub’s form: the name
rghcard, the permission Administration: Read-only and Expiration: none, since the cards stop updating when the token expires. GitHub adds Metadata: Read-only by itself. Choose Repository access: All repositories, click Generate token and copy the token: GitHub shows it only once.In the profile repository, Settings > Secrets and variables > Actions > New repository secret: name it
RGHCARD_TOKENand paste the token.Commit and push the workflow, then run it once: Actions > rghcard > Run workflow.
-
Add the cards you want to
README.md, each in a<picture>like these two; the other cards areactivity,visitors,actionsandcode, anduse_rghcard_action()prints the code of every card it draws:<picture> <source media="(prefers-color-scheme: dark)" srcset="rghcard-contributions-dark.svg"/> <img alt="GitHub contributions" src="rghcard-contributions-light.svg" width="100%"/> </picture> <picture> <source media="(prefers-color-scheme: dark)" srcset="rghcard-stats-dark.svg"/> <img alt="GitHub statistics" src="rghcard-stats-light.svg" width="100%"/> </picture>
Every Monday at 05:17 UTC (schedule changes when), the
workflow runs the action of the latest release of rghcard 0.x,
sedzinfo/rghcard@v0: it collects your statistics, draws the
six cards (cards chooses which) in the dark and the light
theme (themes chooses), as SVG files (format
chooses), and commits them with the history in
rghcard-data/. The inputs of the action, under
with: in the workflow, change the cards: their charts and
days, for example. The README lists
them.
When the token expires or is revoked, the run fails with a message saying so: put a new token in the secret. In a public profile repository, all of it is public: the page views, clones and unique visitors of each repository per day, with its top referring sites and most viewed pages; the downloads of each release file; your GitHub Actions runs, with their times; the bytes of code of each repository in each language and the time of each star; how many followers you have, and how many users you follow; your contributions per day and by type (which your profile shows anyway) and your commits per repository and year. Who visits, clones or stars your repositories is never collected.