Skip to content

Instantly share code, notes, and snippets.

#' Convert an StackOverflow URL to a local filename
#'
#' @param url character string, typically starting with
#' "https://stackoverflow.com/..."
#' @param dir logical, whether this should be a directory or a file
#' @param ext character, file extension
#' @param create logical, whether to create it or just report on it
#' @param force logical, whether to resort to a question number if the
#' user cannot be found
#' @param base character, the path under which all others will be
@r2evans
r2evans / gitlabci.bash
Last active January 28, 2022 14:34
Run GitLab CI jobs locally
#!/bin/bash
# gitlabci, v0.2, 2022-01-28
# Run GitLab-CI jobs (e.g., tests, coverage), locally.
# (c) 2022 Bill Evans bill@8pawexpress.com
# This script is intended to preempt the vicious cycle of:
# - Commit. Push. Watch the online CI test fail.
# - Commit a small typo. Push. Watch the CI test fail.
# - Commit two more characters. Push. Glare at the CI test.
#
#' NDC caching for cross-facet plot elements
#'
#' Useful when using [layout()] and drawing things *between* different
#' plots. Motivated by https://stackoverflow.com/q/49464991/3358272.
#'
#' @details
#'
#' When adding plot "things" (lines, points, arrows) between facets of
#' a `layout` combination, in addition to `x` and `y`, you simply
#' provide the plot number within the sequence. (Since this is the
@r2evans
r2evans / app.R
Created March 11, 2023 15:31
r-shiny-clientdata
# Simple shiny app that shows most of the headers and env-vars as seen
# by the app when visited.
#
# MIT License
# Copyright (c) 2023 Bill Evans <bill@8pawexpress.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
@r2evans
r2evans / plumber.R
Created March 11, 2023 15:35
r-plumber-clientdata
# Simple plumber api that shows most of the headers and env-vars as seen
# by the app when visited.
#
# MIT License
# Copyright (c) 2023 Bill Evans <bill@8pawexpress.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
@r2evans
r2evans / coord_cartesian_panels.R
Last active April 25, 2023 03:54
per-facet panel range clipping
#' Cartesian coordinates per facet-panel
#'
#' This function mimics the behavior of [ggplot2::coord_cartesian()],
#' while supporting per-panel limits when faceted.
#'
#' @details
#'
#' A 'panel_limits' data frame may contain:
#'
#' - zero or more faceting variables, all of which must be found
#' Programmatically produce row-independent `tribble`s
#'
#' @param x data.frame
#' @param max_width integer, the widest normalized width; if data or a
#' header is longer than this, it will not be truncated, but it will
#' also not be aligned with the others; can be single number (for
#' all) or a vector (for each column)
#' @param collapse character, the separation text, defaults to `", "`
#' @param compact logical, "no undue spaces"; if `TRUE` then sets
#' `max_width=0`, `collapse=","`, and disallows prepending