Skip to content

Instantly share code, notes, and snippets.

Avatar

Noam Ross noamross

View GitHub Profile
View cars.csv
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21 6 160 110 3.9 2.62 16.46 0 1 4 4
Mazda RX4 Wag 21 6 160 110 3.9 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.32 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.44 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.46 20.22 1 0 3 1
Duster 360 14.3 8 360 245 3.21 3.57 15.84 0 0 3 4
Merc 240D 24.4 4 146.7 62 3.69 3.19 20 1 0 4 2
Merc 230 22.8 4 140.8 95 3.92 3.15 22.9 1 0 4 2
@noamross
noamross / test-dolt.R
Created Sep 1, 2021
Reprex of trying to write data to Dolt with RMariaDB
View test-dolt.R
library(sys)
library(RMariaDB)
library(DBI)
library(withr)
# Clean up from previous session
unlink("doltdb", recursive = TRUE)
try(dbDisconnect(conn), silent = TRUE)
@noamross
noamross / toggle-radio-layer-legends.R
Created Aug 13, 2021
A quick hack to have the legends associated with radio-button "Base Groups" in R leaflet maps toggle along with layers
View toggle-radio-layer-legends.R
library(leaflet)
library(tidyverse)
outline <- quakes[chull(quakes$long, quakes$lat),]
map <- leaflet(quakes) %>%
addTiles(group = "OSM (default)") %>%
# Overlay groups
addCircles(~long, ~lat, ~10^mag/5, stroke = F, group = "Quakes") %>%
addPolygons(data = outline, lng = ~long, lat = ~lat,
@noamross
noamross / source_rmd.R
Last active Jul 21, 2021
Source an RMD file
View source_rmd.R
#' Source the R code from an knitr file, optionally skipping plots
#'
#' @param file the knitr file to source
#' @param skip_plots whether to make plots. If TRUE (default) sets a null graphics device
#'
#' @return This function is called for its side effects
#' @export
source_rmd = function(file, skip_plots = TRUE) {
temp = tempfile(fileext=".R")
knitr::purl(file, output=temp)
View get_cran_marc_codes.R
library(desc)
library(httr)
library(purrr)
library(stringi)
library(methods)
library(dplyr)
library(tidyr)
pkgs <- rownames(available.packages())
if(!dir.exists("DESCRIPTIONS")) dir.create("DESCRIPTIONS")
@noamross
noamross / criticmarkup.lua
Last active Jun 16, 2021
A pandoc filter for MS Word track changes to criticmarkup
View criticmarkup.lua
-- a lua filter for panodoc
-- run pandoc your_word_doc.docx --track-change=all -t markdown --lua-filter=criticmarkup.lua
-- TODO: Detect substitutions in adjacent insertion/deletions
-- TODO: capture whole comment hightlight rather than just start point of comment
function Span(elem)
if elem.classes[1] and elem.classes[1] == "insertion" then
local opener = { pandoc.RawInline(FORMAT, "{++ ") }
local closer = { pandoc.RawInline(FORMAT, " ++}") }
return opener .. elem.content .. closer
elseif
@noamross
noamross / base_r_plotting_tutorial_koontz_d-rug.r
Created Apr 24, 2015
Back to basics: High quality plots using base R graphics
View base_r_plotting_tutorial_koontz_d-rug.r
### Title: Back to basics: High quality plots using base R graphics
### An interactive tutorial for the Davis R Users Group meeting on April 24, 2015
###
### Date created: 20150418
### Last updated: 20150423
###
### Author: Michael Koontz
### Email: mikoontz@gmail.com
### Twitter: @michaeljkoontz
###
@noamross
noamross / test_rstanarm_gamm4.R
Created Nov 21, 2016
Trying out rstanarm's new GAM support
View test_rstanarm_gamm4.R
library(rstanarm)
library(tidyverse)
library(viridis)
gtemp <- read.delim("http://www.metoffice.gov.uk/hadobs/hadcrut4/data/current/time_series/HadCRUT.4.5.0.0.annual_ns_avg.txt",
sep="", header = FALSE) %>%
select(1,2) %>%
set_names(c("Year", "Temperature"))
st_mod2 <- stan_gamm4(Temperature ~ s(Year), data = gtemp)
@noamross
noamross / angryscrape.R
Last active Jan 21, 2021
In which I scrape WAHIS out of rage
View angryscrape.R
library(httr)
library(rvest)
library(xml2)
library(tidyverse)
# Pretend we are a browser
my_headers = c(Origin="http://www.oie.int",
`Upgrade-Insecure-Requests`="1",
`Content-Type`="application/x-www-form-urlencoded",
`User-Agent`="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36",
@noamross
noamross / DRUG plyr code.R
Last active Dec 25, 2020
Some examples of using the plyr package for data manipulation
View DRUG plyr code.R
## Some examples using the package plyr
library(plyr)
## Example dataset from ggplot
library(ggplot2)
data(mpg)
str(mpg)