Skip to content

Instantly share code, notes, and snippets.

#' 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
@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
@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 / 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
#' 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 / 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.
#
#' 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 / DBI RODBC comparison.R
Created August 15, 2020 02:23
Comparison of DBI/odbc, DBI/RODBCDBI, and RODBC db access for R
## ------------------------------------------------------------------
## SETUP
# docker run -d -p "31433:1433" --name testss \
# -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=Mysecretpassword1" \
# -e "MSSQL_PID=Developer" --cap-add SYS_PTRACE \
# microsoft/mssql-server-linux
# ... and add 'testss' as a DSN in the system- or user- odbc configuration
@r2evans
r2evans / lazyExpandGrid.R
Last active June 6, 2020 00:22
lazy evaluation of a potentially very large expand.grid
#' Lazy expand.grid.
#'
#' Provide a lazy-eval for expand.grid, similar to python's
#' \code{xrange}, where the source may be too large to be fit into
#' memory but still accessible.
#'
#' This function returns a list of functions for accessing the lazy
#' \code{expand.grid}.
#'
#' The available methods within each object:

Clipboard selection over remote (ssh) and optionally multi-plexed (tmux) connections. This is primarily from a windows machine using git-for-windows, mintty, and tmux remotely. Untested otherwise.

Other (non-Windows) solutions/recommendations include xclip on the remote end; these will not work unless there is an X-windows server running on the local (Windows) machine.

The remainder is effectively the results of my trial-and-error process.

mintty and OSC-52

Instead, this uses OSC-52 escape sequences. Because they can be considered a security risk (the remote end might be able to see the local end's clipboard values arbitrarily), the capability is disabled by default.