Skip to content

Instantly share code, notes, and snippets.

View ateucher's full-sized avatar

Andy Teucher ateucher

View GitHub Profile
@ateucher
ateucher / rmdimage-replace.md
Last active October 6, 2025 22:26
Custom chores helper to replace knitr::include_graphics() with native markdown image syntax

Replace knitr::include_graphics() with native markdown image syntax

You are a terse assistant designed to help Quarto users replace R computational code chunks that use knitr::include_graphics() with an image link using markdown syntax ![](){}.

Use the file path (the first argument in knitr::include_graphics()) as the image path in the () of the new markdown block. Preserve all of the metadata tags in the R chunk (those prefixed with #| in the body of the chunk, or within the curly braces in the chunk header), especially figure alignment (fig-align or fig.align), width (out-width or out.width), and alt text (fig-alt or fig.alt). These go in the {} of the new markdown block. Ignore the line with #| echo: false.

Respond with only the needed markdown text, no backticks or newlines around the response.

As example, given a code chunk like this:

@ateucher
ateucher / xarray-to-terra-with-reticulate.R
Created May 9, 2025 19:15
xarray to terra with reticulate
library(reticulate)
library(terra)
py_require(c("xarray", "netcdf4", "numpy"))
xr <- import("xarray")
np <- import("numpy")
url <- "https://psl.noaa.gov/thredds/dodsC/Datasets/noaa.oisst.v2.highres/sst.day.mean.2022.nc"
library(duckdb)
#> Loading required package: DBI
library(glue)

url <- "http://www.env.gov.bc.ca/wsd/data_searches/water/Discharge.csv"

conn <- DBI::dbConnect(duckdb(), ":memory:")

# Install and load duckdb extensions to read from http
library(arrow)
#> 
#> Attaching package: 'arrow'
#> The following object is masked from 'package:utils':
#> 
#>     timestamp
library(duckdb)
#> Loading required package: DBI
library(dplyr)
@ateucher
ateucher / extract_pptx_notes.R
Last active May 19, 2022 23:48
Extract notes from a pptx slide and export to markdown or docx
extract_pptx_notes <- function(pp_file, format = c("md", "docx")) {
if (!requireNamespace("officer", quietly = TRUE))
stop("pacakge 'officer' required.")
if (!requireNamespace("xml2", quietly = TRUE))
stop("pacakge 'xml2' required.")
if (!requireNamespace("rmarkdown", quietly = TRUE))
stop("pacakge 'rmarkdown' required.")
if (!requireNamespace("glue", quietly = TRUE))
stop("pacakge 'glue' required.")
author date output title
ateucher
2021-06-08
reprex::reprex_document
ash-crane_reprex.R
library(osmdata)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
@ateucher
ateucher / bc-hydro-outages.R
Created May 6, 2021 23:36
bc-hydro-outages.R
library(sf)
library(jsonlite)
library(purrr)
library(mapview)
f <- read_json("https://www.bchydro.com/power-outages/app/outages-map-data.json")
polys <- lapply(f, function(x) {
mat <- matrix(unlist(x$polygon), ncol = 2, byrow = TRUE)
st_polygon(list(rbind(mat, mat[1,])))
@ateucher
ateucher / covid-canada.R
Last active December 3, 2020 00:24
covid-canada.R
library(tidyverse)
library(gghighlight)
library(ggrepel)
library(scales)
data <- read_csv("https://github.com/CSSEGISandData/COVID-19/raw/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv")
data_long <- pivot_longer(data, `1/22/20`:last_col(), names_to = "date", values_to = "cases") %>%
mutate(date = as.Date(date, format = "%m/%d/%y")) %>%
filter(!is.na(cases),
library(ggplot2)

iris$is_pretty <- sample(c(TRUE, FALSE), nrow(iris), replace = TRUE)

# dodge < width
ggplot(iris, aes(y = is_pretty, x = Petal.Length, fill = Species)) + 
  geom_bar(stat = "identity", position = position_dodge(0.5), width = 0.85)

*.png
*.pdf
.DS_Store
.Rhistory