Skip to content

Instantly share code, notes, and snippets.

View h-a-graham's full-sized avatar

Hugh Graham h-a-graham

View GitHub Profile
@jrosell
jrosell / sse.R
Created March 2, 2026 20:43
HTTP streaming and Server-Sent Events in R with nanonext
# pak::pak("r-lib/nanonext")
library(nanonext)
conns <- list()
handlers <- list(
handler_stream("/stream",
on_request = function(conn, req) {
conn$set_header("Content-Type", "application/x-ndjson")
conns[[as.character(conn$id)]] <<- conn
conn$send('{"status":"connected"}\n')
@sj-io
sj-io / CLAUDE.md
Created August 21, 2025 09:25
Claude R Tidyverse Expert

Modern R Development Guide

This document captures current best practices for R development, emphasizing modern tidyverse patterns, performance, and style. Last updated: August 2025

Core Principles

  1. Use modern tidyverse patterns - Prioritize dplyr 1.1+ features, native pipe, and current APIs
  2. Profile before optimizing - Use profvis and bench to identify real bottlenecks
  3. Write readable code first - Optimize only when necessary and after profiling
  4. Follow tidyverse style guide - Consistent naming, spacing, and structure
                             Apache License
                       Version 2.0, January 2004
                    http://www.apache.org/licenses/

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

  1. Definitions.

"License" shall mean the terms and conditions for use, reproduction,

https://github.com/openlandmap/GEDTM30?tab=readme-ov-file

gdalinfo /vsicurl/https://s3.opengeohub.org/global/edtm/legendtm_rf_30m_m_s_20000101_20231231_go_epsg.4326_v20250130.tif

Driver: GTiff/GeoTIFF
Files: /vsicurl/https://s3.opengeohub.org/global/edtm/legendtm_rf_30m_m_s_20000101_20231231_go_epsg.4326_v20250130.tif
Size is 1440010, 600010
Coordinate System is:
x_from_col <- function(dimension, bbox, col) {
  col[col < 1] <- NA
  col[col > dimension[1L]] <- NA
  xres <- diff(bbox[c(1, 3)]) / dimension[1]
  bbox[1] - xres/2 + col * xres
}
y_from_row <- function(dimension, bbox, row) {
  row[row < 1] <- NA
  row[row > dimension[2]] <- NA
@GMoncrieff
GMoncrieff / how_i_work.md
Last active October 28, 2025 20:27
How I do ML with geospatial data

How I do machine learning with geospatial data

I have a couple of AI/ML projects related to mapping things, often conservation related, with remote sensing data. Some details and packages will vary, but the process below describes how I generally approach these types of problems. Some of these tools I have only touched briefly, but I like them, and this is more an outline of how I would like to approach a new project than a retrospective look at my previous work.

We use AWS, so it makes sense to use datasets and services that are already hosted on AWS. The data discovery and loading part of this process would look somewhat different if we were using Azure and Planetary Computer, and very different if we were using GCP and Earth Engine.

Compute

All of my analysis will be done using python on an AWS VM in the same region as my data on S3, Probably using VSCode on Sagemaker or [JupyterLab](https://docs.aws.amazo

Here is some code to explore the variety available in calculating area across various packages.

x <- rnaturalearth::ne_countries(country = c("Greenland", "Spain"), returnclass = "sf")
as.numeric(sf::st_area(x))/1e6

## Greenland 2.166e6 km²  -41, 72
## Spain     505990 km²   -2, 40
@mikemahoney218
mikemahoney218 / tidy_geocomp.R
Last active August 31, 2022 07:21
Proof-of-concept replication of https://geocompr.robinlovelace.net/spatial-cv.html with tidymodels
# 12.5 Spatial CV (with spatialsample)
library(tidymodels)
library(spatialsample)
library(sf)
data("lsl", "study_mask", package = "spDataLarge")
lsl <- lsl |>
st_as_sf(coords = c("x", "y"), crs = "EPSG:32717")
ta <- terra::rast(system.file("raster/ta.tif", package = "spDataLarge"))
@anthonynorth
anthonynorth / data_pipeline.R
Last active March 21, 2022 22:44
gb rivers
library(dplyr)
library(sf)
if (!file.exists("rivers_gb.rds")) {
download.file(
"https://beaver-net-app.s3.eu-west-2.amazonaws.com/gb_rivers/rivers_gb.rds",
"rivers_gb.rds"
)
}