Skip to content

Instantly share code, notes, and snippets.

require 'securerandom'
class NameGenerator
LEFT = [
"admiring",
"adoring",
"affectionate",
"agitated",
"amazing",
"angry",
library(tidyverse)
## approximates big_df in the post
big_df <- mtcars %>%
select(cyl, mpg, disp) %>%
arrange(cyl) %>%
slice(17:22) %>%
rename(ID = cyl)
## dummy function that needs access to ID and data
@tjmahr
tjmahr / snippet.txt
Last active July 13, 2018 15:32
bookdown figure snippet
snippet bdfig
Figure \@ref(fig:${1:chunk-name}) ${0}
(ref:${1:chunk-name}) Text reference for caption
```{r ${1:chunk-name}, fig.cap = "(ref:${1:chunk-name})"}
```
@hrbrmstr
hrbrmstr / gg_tweet.R
Last active October 16, 2020 04:49
use the magick device to make ggplots conform to twitter card or in-stream image optimal sizes, with or without "retina" resolution
library(httr)
library(magick)
library(hrbrthemes)
library(ggplot2)
theme_tweet_rc <- function(grid = "XY", style = c("stream", "card"), retina=TRUE) {
style <- match.arg(tolower(style), c("stream", "card"))
switch(
@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")
@bearloga
bearloga / upgrade_packages.R
Last active October 8, 2020 12:46
The script can be used to re-install packages after upgrading R (on Linux or Mac), since libraries cannot be reused between different minor versions (e.g. when upgrading 3.2.3 to 3.3.2). It detects when a package was installed from CRAN vs GitHub/Git and re-installs it using the appropriate func. Usage: `Rscript upgrade_packages.R`
# WMF only:
if (file.exists("/etc/wikimedia-cluster")) {
message('Detected that this script is being run on a WMF machine ("', Sys.info()["nodename"], '"). Setting proxies...')
Sys.setenv("http_proxy" = "http://webproxy.eqiad.wmnet:8080")
Sys.setenv("https_proxy" = "http://webproxy.eqiad.wmnet:8080")
}
# General use:
message("Checking for a personal library...")
if (!dir.exists(Sys.getenv("R_LIBS_USER"))) {
@jeroen
jeroen / favicon.R
Last active February 14, 2019 21:32
Generate favicon with magick
library(magick)
library(magrittr)
# Convert to 'ico' format
image_read("https://www.r-project.org/logo/Rlogo.png") %>%
image_scale("32x32!") %>% # remove the "!" after 32x32 to scale proportionally
image_write("favicon.ico", format = "ico")
# Favicon can also be png/gif
@aschleg
aschleg / games_howell.R
Last active November 29, 2017 00:07
R function for performing Games-Howell Post-Hoc Test
games.howell <- function(grp, obs) {
#Create combinations
combs <- combn(unique(grp), 2)
# Statistics that will be used throughout the calculations:
# n = sample size of each group
# groups = number of groups in data
# Mean = means of each group sample
# std = variance of each group sample
county sample state name exceedances
Mobile 20 al Dauphin Island Water & Sewer 1
Monroe 23 al Excel Water System 1
Washington 95 al Tate & Lyle Sucralose, Inc. Water System 1
Coosa 18.3 al Lake Mitchell Water, Incorporated 1
Juneau City and Borough 15.5 ak Thunder Mountain Mobile Park 1
Juneau City and Borough 31 ak Hecla Greens Creek Hawk Inlet 1
Ketchikan Gateway Borough 27.7 ak Boyer Towing 1
Ketchikan Gateway Borough 32.9 ak Thorne Bay, City Of 1
Ketchikan Gateway Borough 16.2 ak Clover Pass Christian School 2