Skip to content

Instantly share code, notes, and snippets.

View gregorp's full-sized avatar

Gregor Thomas gregorp

View GitHub Profile
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::project-evident-cnmi",
"Condition": {
"StringEquals": {
@gregorp
gregorp / coffee.r
Created November 29, 2021 19:19
R coffee joke
while(working) {
drink(coffee)
do(work)
if(is_empty(coffee)) {
if(is_empty(cofeepot)) {
coffeepot <- brew(coffeepot)
}
coffee <- refill(coffee)
}
}
@gregorp
gregorp / check-gpl3-deps.r
Last active January 31, 2019 15:39
Check R package dependency tree for GPL-3 package
get_license_info = function() {
lic_info = available.packages(filters = c("CRAN", "duplicates"),
fields = "License")[, c("Package", "License")]
lic_info = as.data.frame(lic_info, stringsAsFactors = FALSE)
# take a stab at identifying GPL 3 packages without other license options
lic_info$GPL3 = grepl("GPL.*3", lic_info$License) & !grepl("\\|", lic_info$License)
return(lic_info)
}
@gregorp
gregorp / lmer-list-vs-dataframe.r
Last active January 19, 2018 19:41
Investigating alleged differences in `lmer` results depending on whether the input is in a list or not
library(lmer)
library(lmerTest)
# Comparing the `lmer` output on identical data frames, one in a list, one not.
# This example uses data built in to the `lme4` package, and the model in the `?lmer` help examples.
## split data into two groups by subject
subject_sample = sample(unique(sleepstudy$Subject), size = length(unique(sleepstudy$Subject)) / 2)
sleep_split = split(sleepstudy, f = sleepstudy$Subject %in% subject_sample)
# p1 (1-10) is attribute - determines d: number of sides of dice
# p2 (1-10) is skill - determines k: number of dice to keep
# p1 + p2 determines n: the number of dice to roll
pp = expand.grid(p1 = 1:10, p2 = 1:10)
library(dplyr)
library(tidyr)
pp = pp %>% mutate(
@gregorp
gregorp / samp.R
Last active August 29, 2015 13:56
samp functions for small random subsets
#' Sample of an object.
#'
#' Shortcut for checking on data.
#' @rdname samp
#' @param x data.frame (or matrix) to sample from
#' @param n number of rows to sample (default is 10)
#' @return n random rows of x
#' @export
samp <- function(x, n) {
UseMethod("samp")