Skip to content

Instantly share code, notes, and snippets.

View jennybc's full-sized avatar

Jennifer (Jenny) Bryan jennybc

View GitHub Profile
@jennybc
jennybc / reverse-categorical-axis-ggplot2.r
Created October 10, 2014 01:06
Reverse the order of a categorical axis in ggplot2
scale_x_discrete(limits = rev(levels(the_factor)))
@jennybc
jennybc / github-pat-checksum.R
Created January 20, 2024 16:20
Noodling with the GitHub PAT checksum
pat <- gitcreds::gitcreds_get()
cksum <- digest::digest(
substr(pat$password, start = 5, stop = nchar(pat$password) - 6),
algo = "crc32", serialize = FALSE
)
# https://stackoverflow.com/q/5478508
toBase <- function(num, base=62) {
# bv <- c(seq(0,9),letters,LETTERS)
# GitHub seems to do UPPERCASE then lowercase
@jennybc
jennybc / 2014-12-01_finessing-excel-line-endings.md
Last active November 17, 2022 13:04
Finessing Excel's stupid line endings

Finessing Excel's stupid line endings

I am sheepish to admit a certain type of routine Microsoft Excel use.

Current example: I am marking for STAT 545. I use R to create a comma delimited marking sheet, by joining the official class list and peer reviews. The sheet contains variables, initially set to NA, where the TAs and I enter official marks and optional comments.

This is where Excel comes in. I like its visual organization of this comma delimited file much more than, say, using a plain text editor. I use the ability to hide columns, resize columns, wrap text, and (gasp!) even fill rows with grey to indicate I am done.

I keep saving the file as comma delimited and I put up with Excel's incessant freak out about "losing features". This is not a one time thing. I need to save and commit this file many times before it is considered done.

@jennybc
jennybc / 2014-10-12_stop-working-directory-insanity.md
Last active September 23, 2022 04:43
Stop the working directory insanity

There are packages for this now!

2017-08-03: Since I wrote this in 2014, the universe, specifically Kirill Müller (https://github.com/krlmlr), has provided better solutions to this problem. I now recommend that you use one of these two packages:

  • rprojroot: This is the main package with functions to help you express paths in a way that will "just work" when developing interactively in an RStudio Project and when you render your file.
  • here: A lightweight wrapper around rprojroot that anticipates the most likely scenario: you want to write paths relative to the top-level directory, defined as an RStudio project or Git repo. TRY THIS FIRST.

I love these packages so much I wrote an ode to here.

I use these packages now instead of what I describe below. I'll leave this gist up for historical interest. 😆

@jennybc
jennybc / twee-demo.Rmd
Last active August 14, 2022 21:50
twee(): emulating the tree directory listing command
---
title: "twee demo"
author: "Jenny Bryan"
date: "17 August, 2014"
output:
html_document:
toc: TRUE
keep_md: TRUE
---
@jennybc
jennybc / 2015-03-02_plot-next-to-table.rmd
Last active June 30, 2022 19:46
Quicky and dirty: side-by-side plot and table
---
title: "Quicky and dirty: side-by-side plot and table"
author: "Omar AlOmeir"
output:
html_document:
css: two_columns.css
---
Code from Omar AlOmeir, posted by Jenny Bryan
@jennybc
jennybc / photo-gallery-README.R
Last active April 3, 2022 19:21
Generate a photo-gallery README for a directory of figs
@jennybc
jennybc / yaml_frontmatter_r_github_document.yaml
Last active February 9, 2022 21:36
YAML frontmatter for R Markdown to cause rmarkdown::render() to retain intermediate Markdown file for .R and .Rmd files, respectively
#' ---
#' title: "Something fascinating"
#' author: "Jenny Bryan"
#' date: "`r format(Sys.Date())`"
#' output: github_document
#' ---
@jennybc
jennybc / 2015-08-06_nested-render-confuses-rstudio.Rmd
Last active March 22, 2021 18:50
Nested render confuses RStudio
---
output:
html_document
---
```{r setup, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
@jennybc
jennybc / miles.md
Last active February 25, 2021 07:05
A rowwise summary problem where we don't want to use `rowwise()`
library(tidyverse)

(df <- tibble(
  id = 1:3,
  wut = letters[3:1],
  x1 = 1:3,
  x2 = 4:6,
  x3 = 7:9
))