Skip to content

Instantly share code, notes, and snippets.

View njtierney's full-sized avatar
👷‍♂️
Available for work!

Nicholas Tierney njtierney

👷‍♂️
Available for work!
View GitHub Profile
@DavisVaughan
DavisVaughan / r-print.c
Last active September 20, 2024 17:24
r-print-value-from-c
#include <R_ext/Parse.h>
const char* r_print_value(SEXP x) {
// Assign `x` into the global environment under the name `.debug`
Rf_defineVar(Rf_install(".debug"), x, R_GlobalEnv);
// This is the R code that we want to run to print `.debug` and then capture all its printed output
const char* command = "paste0(capture.output(print(.debug)), collapse = '\n')";
SEXP command_sexp = PROTECT(Rf_allocVector(STRSXP, 1));
SET_STRING_ELT(command_sexp, 0, Rf_mkCharCE(command, CE_UTF8));
@JosiahParry
JosiahParry / keybindings.json
Last active August 17, 2024 00:46
Positron Keybindings
// Place your key bindings in this file to override the defaults
[
{
"key": "shift+cmd+b",
"command": "workbench.action.tasks.runTask",
"args": "Build R package",
"when": "isRPackage"
},
{
"key": "shift+cmd+enter",
@juliasilge
juliasilge / installation.md
Last active April 22, 2024 21:04
Installing R + Tensorflow on M1
@tylermorganwall
tylermorganwall / india_historical_map.R
Last active February 25, 2024 18:22
Historical Map of India with 3D elevation
library(raster)
library(rayshader)
#Load QGIS georeference image (see https://www.qgistutorials.com/en/docs/3/georeferencing_basics.html)
testindia = raster::stack("1870_southern-india_modified.tif")
#Set bounding box for final map (cut off edges without data, introduced via reprojection)
india_bb = raster::extent(c(68,92,1,20))
cropped_india = raster::crop(testindia, india_bb)
#Convert to RGB array
@nstrayer
nstrayer / simulate_mnar_data.R
Created January 21, 2020 21:38
R Script to simulate missing not at random data and look at performance of different imputation strategies.
library(tidyverse)
n <- 150
sensitivity_threshold <- 5
data <- tibble(
a = rgamma(n = n, shape = 5, rate = 0.5),
b = rgamma(n = n, shape = a/2, rate = 0.5)
)
generate_missing_data <- function(i){
@coolbutuseless
coolbutuseless / css.R
Created August 18, 2019 09:49
CSS helper
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#' Create a CSS ruleset
#'
#' Create a CSS ruleset consisting of a selector and one-or-more property declarations,
#' or, if no \code{.selector} is given, create an inline style string
#'
#' The list of included properties is not a complete list, but rather an
#' abbreviated list from
#' \url{https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Properties_Reference}
@MilesMcBain
MilesMcBain / fools_five.R
Last active July 17, 2019 03:11
Fool's five
f <- function(...) {
function(df) with(df, ...)
}
footate <- function(.data, ...) {
dots <- list(...)
for (column in names(dots)) {
.data[[column]] <- dots[[column]](.data)
}
@markdly
markdly / html-multiple-choice.Rmd
Last active January 31, 2024 22:24
Multiple choice quiz question Rmarkdown
---
output:
html_document:
theme: cerulean
---
### Example html multiple choice question using Rmarkdown
<!-- Render this Rmarkdown doc to html to make an interactive html / js multiple choice question -->
@trestletech
trestletech / analysis.R
Last active July 7, 2017 16:49
Tidying of pressure-sensitive keystroke dynamics data. Raw available: https://figshare.com/articles/Pressure-sensitive_keystroke_dynamics_data/5170705 . The `isJA` column represents whether or not the user currently typing is "Jeffrey Allen" -- i.e. is the user typing his own name (TRUE) or someone else's (FALSE)?
download.file("https://ndownloader.figshare.com/articles/5170705/versions/1", "kd.zip")
unzip("kd.zip")
library(readr)
words <- readr::read_csv("KSP-Word.csv")
users <- readr::read_csv("KSP-User.csv")
entries <- readr::read_csv("KSP-Entry.csv")
keypress <- readr::read_csv("KSP-KeyPress.csv")
pressure <- readr::read_csv("KSP-Pressure.csv")
dat <- readr::read_csv("municipality\n- Ticino\n>> Distretto di Bellinzona\n......5001 Arbedo-Castione\n......5002 Bellinzona\n......5003 Cadenazzo\n......5004 Camorino\n")
dat %>% mutate(municipality = gsub(pattern = '[\\.\\>]|^-',
replacement = "",
municipality)) %>%
separate(col = municipality,
sep = '(?<=[0-9])\\s',
into = c ("code","municipality"),
fill = "left")