Skip to content

Instantly share code, notes, and snippets.

View mpadge's full-sized avatar
🤹‍♀️
Coding away ...

mark padgham mpadge

🤹‍♀️
Coding away ...
View GitHub Profile
@PietrH
PietrH / check_similar_fn_args.R
Created July 8, 2024 10:04
check for similarly named function arguments in an R package
Library(dplyr)
# Which package to check
trias_namespace <- asNamespace("trias")
# Character vector of all functions and their arguments, print method of base ls with str() on every object
trias_fns_args <- capture.output(utils::lsf.str(trias_namespace))
# Extract the functions
@OrionReed
OrionReed / dom3d.js
Last active July 22, 2024 08:58
3D DOM viewer, copy-paste this into your console to visualise the DOM topographically.
// 3D Dom viewer, copy-paste this into your console to visualise the DOM as a stack of solid blocks.
// You can also minify and save it as a bookmarklet (https://www.freecodecamp.org/news/what-are-bookmarklets/)
(() => {
const SHOW_SIDES = false; // color sides of DOM nodes?
const COLOR_SURFACE = true; // color tops of DOM nodes?
const COLOR_RANDOM = false; // randomise color?
const COLOR_HUE = 190; // hue in HSL (https://hslpicker.com)
const MAX_ROTATION = 180; // set to 360 to rotate all the way round
const THICKNESS = 20; // thickness of layers
const DISTANCE = 10000; // ¯\\_(ツ)_/¯
@mdsumner
mdsumner / discrete-vs-continuous-mesh.R
Last active September 4, 2019 19:54
Mesh plot with raster / quadmesh, and types of meshes
## latest needed for recent bug fix in triangles
## remotes::install_github("hypertidy/quadmesh")
library(quadmesh)
r <- quadmesh::etopo
## volcano as a raster in 0:nr, 0:nc (just because it's small and familiar)
v <- raster::raster(volcano, xmn = 0, xmx = nrow(volcano), ymn = 0, ymx = ncol(volcano))
v <- raster::aggregate(v, fact = 2)
## 2D plot in any projection
@krlmlr
krlmlr / Rprofile-entrace
Last active January 7, 2021 01:59
Pretty stack traces in R
# Add this to your .Rprofile
options(
error = quote(rlang::entrace()),
rlang__backtrace_on_error = "collapse" # or "branch" or "full"
)
@beemyfriend
beemyfriend / latticeWObstaclesTopology.R
Created July 16, 2018 01:54
Exploring graph substructures with topological obstacles (missing nodes) and node weights
library(tidyverse)
library(igraph)
####
# The pattern is to identify points to extend the structure of
# dyads and subsequent structures
# And make sure the extension isn't already part of the structure
####
@beemyfriend
beemyfriend / latticeWObstacles.R
Created July 15, 2018 04:47
Exploring graph substructures with topological obstacles (missing nodes)
####
# Dependencies
####
library(tidyverse)
library(igraph)
####
# The pattern is to identify points to extend the structure of
@goldingn
goldingn / multiple_progress.R
Last active May 21, 2018 00:50
multiple progress bars on a single line, to be combined with parallel_progress.R
# plotting multiple progress bars on the same line, as a precursor to running
# the progress bars in parallel
library (progress)
library (future)
library (R6)
new_connection <- function () {
f <- tempfile()
file.create(f)
@goldingn
goldingn / parallel_progress.R
Created April 14, 2018 00:50
prototype of parallel progress reporting (for processes on the same file system)
# progress information in parallel processes (that use the same filesystem)
# the master function sets up a tempfile for each process, spawns processes, and
# passes the corresponding tempfile location to each; each process dumps
# progress information into its tempfile; the master function polls those files
# for the progress information and returns it to the screen; the previous line
# is overwritten, as for progress bars
library (future)
# an environment to stash file info in, to hack around scoping issues. A package
library(silicate)
data("wrld_simpl", package = "maptools")
#edges are unique segments (undirected)
#segments are directed instances of edges, belonging to arcs/ways or feature boundaries
library(silicate)
library(sf)
x <- PATH(st_as_sf(wrld_simpl))
#x <- PATH(minimal_mesh)
@hrbrmstr
hrbrmstr / newpkg.sh
Created December 27, 2015 17:56
R package skeleton maker
#!/bin/bash
# AUTHOR: Bob Rudis <bob@rudis.net> (@hrbrmstr)
# LICENSE: MIT + file zLICENSE
TODAY=`date +%Y-%m-%d`
TODAY_MD=`date +%B\ %d,\ %Y`
YEAR=`date +%Y`
PACKAGENAME=$1