Skip to content

Instantly share code, notes, and snippets.

View johnmackintosh's full-sized avatar

John MacKintosh johnmackintosh

View GitHub Profile
CreateProjectFiles <- function(PROJECT_PATH = rstudioapi::getActiveProject(),
FOLDERS_TO_CREATE = c("data", "docs", "figs", "logs",
"output", "queries", "R", "tests"),
OPEN_NEW_SESSION = TRUE,
DEBUG = TRUE){
if(DEBUG) message("CreateProjectFiles: Function initialized \n")
if(!dir.exists(PROJECT_PATH)){
@jasonpott
jasonpott / purrr_map_multiple_event_extract.R
Created December 10, 2021 20:11
Method to extract sequential events for a defined population in MS SQL via dbplyr / purrr / R
# con is a connection object
#Package load
pacman::p_load(tidyverse, tidylog, janitor, pool,odbc, dbplyr)
dbConnect(
odbc(),
Driver = "SQL Server",
Server = "server name",
@matt-dray
matt-dray / runcharter-badges.R
Last active November 9, 2021 22:22
The {runcharter} package by John MacKintosh needs more badges
install.packages(c("remotes", "tibble", "purrr"))
remotes::install_github("matt-dray/badgr")
tibble::tribble(
~label, ~message,
"years", "8",
"kids", "2",
"late nights", "ridiculous",
"sleep missed", "weeks",
"pringles", "way too many",
@xenatisch
xenatisch / cache_repopulation.sql
Last active November 18, 2021 19:36
Query to repopulate cache for postcode pages of the UK Coronavirus Dashboard
SELECT
'area-' || release_date::TEXT || '-' || area_id::TEXT AS key,
JSONB_AGG(
JSONB_BUILD_OBJECT(
'area_code', area_code,
'area_type', area_type,
'area_name', area_name,
'date', to_char(date::DATE, 'YYYY-MM-DD'),
'metric', metric,
'value', value,
@jph00
jph00 / epi_sir_basic.ipynb
Created September 12, 2021 12:59
Basic SIR epidemic model
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@davebraze
davebraze / emacs-data-work.md
Last active July 17, 2025 16:01
On using Emacs for data work with R

I use GNU Emacs on MS Windows 11, specifically, the pre-packaged pre-compiled distributions for Windows provided by Vince Goulet (https://vigou3.gitlab.io/emacs-modified-windows/). He also provides a bundle for MacOS (https://vigou3.gitlab.io/emacs-modified-macos/). I have used, and occassionally still use, Emacs on a variety of different unixen. I believe most of what follows will apply to any GNU Emacs distribution or derivative on any platform, but of course, YMMV.

By way of background, I've been using Emacs since the late 80s as an IDE for various programming languages (e.g., pascal, C, lisp, matlab, python), and as a general text editor. I've also got a lot of mileage out of it's features for calendaring, scheduling, note-taking, and agenda making. So, when I started using R around 2001, it was natural to do my R scripting and programming in Emacs (using its ESS package, which I'd already been using with SAS since the early 90s). When RStudio came out in about 2011, I did give it a look, but it was

@simmwill
simmwill / iterative_DBI_pulls.R
Last active March 16, 2022 14:44
Execute iterative SQL queries from R using purrr functions
library(DBI)
library(ODBC)
library(purrr)
.con <- dbConnect(odbc(),
Driver = "MySQL ODBC 8.0 ANSI Driver",
Server = x,
Database = y,
Port = 3306,
uid = u,
@tomjemmett
tomjemmett / reinstall_steps.md
Last active May 3, 2023 15:43
reinstall r packages after an upgrade

Reinstall R packages after an upgrade

Packages that you install in R are tied to a particular version of R, so after installing a new version none of your previously installed pacakges will remain. I tend to think of this as a feature (time for a spring clean...), and then just reinstall pacakges that I know I need (e.g. install.packages(c("tidyverse", "usethis", "devtools"))) and continue to install pacakges as I realise that I need them.

However, if you really want to reinstall the previous set of packages, the steps below will help. First, we collect a list of packages that were installed from CRAN and a list of packages that were installed from GitHub repositories. Once we have those lists, after intalling the new version of R we can load the list of those packages and reinstall them.

@thisisnic
thisisnic / pre-commit
Created August 26, 2021 17:03
pre-commit file which runs styler on everything
#!/bin/bash
set -e
SOURCE_DIR='<path_to_project_root_goes_here>'
# Find all .R files which have been staged via git add
FILES_TO_STYLE=$(git diff --name-only --staged | grep "\.R")
for FILE in ${FILES_TO_STYLE[@]}
do
---
title: "Loop demo"
author: "Chris Beeley"
date: "21/04/2021"
output: html_document
params:
species: NA
---
```{r setup, include=FALSE}