Skip to content

Instantly share code, notes, and snippets.

@benmarwick
benmarwick / inspect-rmd-diff-from-last-commit.R
Last active February 8, 2024 21:17
GitHub doesn't show rich diffs for Rmd files. That can make collaborative writing tough. Here's how to see rich diffs of two commits of a single R Markdown document on a GitHub repo or local Git repo
# another method
# remotes::install_github("ropenscilabs/reviewer")
browseURL(reviewer::diff_rmd("analysis/paper/paper.qmd",
# this gets the sha of the previous commit
git2r::commits(n=2)[[2]]$sha)$raw)
@benmarwick
benmarwick / archy-course-schedule-overlaps.qmd
Last active February 7, 2024 17:03
ARCHY course time overlaps
---
title: "AY24-25 ARCHY course time overlaps"
format: html
execute:
echo: false
warning: false
self-contained: true
---
@benmarwick
benmarwick / gist:44959d24ef6e53c86d3bd8aed83dffd5
Created January 18, 2024 07:57
Archaeology job ads from Archaeology Jobs Wiki
library(tidyverse)
base_url <- "http://academicjobs.wikia.com/wiki/Archaeology_Jobs_"
# starts at 2010-2011
years <- map_chr(2010:2019, ~str_glue('{.x}-{.x +1}'))
# though it seems to start at 2007-8: https://academicjobs.fandom.com/wiki/Archaeology_07-08
urls_for_each_year <- str_glue('{base_url}{years}')
@benmarwick
benmarwick / gist:2237a297a33c8cb26053a526a192333e
Last active November 4, 2023 08:17
What time of the day do people post their SOTA spots?
library(httr2)
library(tidyverse)
library(sf)
library(lutz)
library(hms)
req <- request("https://api2.sota.org.uk/api/")
# get associations so we can get their time zones via lat-long
resp <- req %>%
# This script was prepared for ARCHY 486 AU23. It will draw a plot of particle size distribution
# of multiple sediment samples on a log scale with major size categories indicated for easy
# comparison. The data should be formatted as in this sheet:
# https://docs.google.com/spreadsheets/d/11RfkGzjpeAT1MAt1w-L5HFgdqzX_kNcXeX3EymvIBpo/edit#gid=390081773
# with column names exactly as found there.
# get raw data on mass of sediment in the sieves
sieve_measurements <-
lab_data_my_group %>%
select(sieve_starting_mass_g,
# following example from https://tensorflow.rstudio.com/tutorials/keras/classification
# do these steps first : https://tensorflow.rstudio.com/install/
library(keras)
library(tidyverse)
library(png)
library(magick)
# get images into R
imgs <-
@benmarwick
benmarwick / random-group-assignment.R
Last active October 2, 2023 05:53
Randomly assign students into seminar reading groups of equal sizes, different groups each week
# get canvas gradebook as CSV...
library(tidyverse)
students <-
readr::read_csv("2023-10-01T2053_Grades-ARCHY_482_A.csv") %>%
# exclude test student
filter(!is.na(`SIS User ID`)) %>%
select(Student) %>%
as.data.frame()
@benmarwick
benmarwick / giur-zones-with-ggplot2.R
Last active June 18, 2023 02:58
Geometric Index of Unifacial Retouch Zone visualisation with ggplot2
library(ggplot2)
# coords for vertices of polygons that make the zones
polydata <- rbind(
data.frame(x = c(0, 0.01, 0.99, 1),
y = c(0, 0.25, 0.25, 0),
group = "zone 1",
fill = "grey80", xc = .5, yc = 0.125),
data.frame(x = c(0, 0.025, 0.495, 0.495),
y = c(-0.01, -0.25, -0.25, -0.01),
@benmarwick
benmarwick / gist:70f92dd61700abab1b590afa0040e3fa
Created April 27, 2018 22:17
using sf for points in polygon spatial join
library(sf)
library(tidyverse)
# read in the shapefile first, that gives us the CRS for the analysis
polygons <- st_read("polygons.shp")
# read in the points
points <- read_csv('points.csv')
@benmarwick
benmarwick / violin-prices.R
Last active April 29, 2023 21:40
Get violin auction prices from a few websites and plot
library(rvest)
url <- "https://www.maestronet.com/history/makers_list.cfm?ID=1"
links_on_page <-
url %>%
read_html() %>%
html_nodes(".text a") %>%