Skip to content

Instantly share code, notes, and snippets.

Avatar

Noam Ross noamross

View GitHub Profile
@noamross
noamross / mgcv-posterior-animate.R
Created Sep 2, 2018
Animating smoothing uncertainty in a GAM
View mgcv-posterior-animate.R
library(tidyverse)
library(gganimate)
library(mgcv)
library(mvtnorm)
# Fit a GAM to the data
mod <- gam(hp ~ s(mpg), data=mtcars, method="REML")
# Get the linear prediction matrix
newdat = data.frame(
@noamross
noamross / rs_term_editor.sh
Last active Aug 30, 2018
An experiment in trying to make RStudio GIT_EDITOR for terminal sessions
View rs_term_editor.sh
#!/bin/bash
# Put this file somewhere and run
# export EDITOR=/path/to/rs_term_editor.sh
# export GIT_EDITOR=/path/to/rs_term_editor.sh
# There's probably some way to set thes e in my profile to only run
# when RSTUDIO=1
### Set initial time of file
LTIME=`stat -f "%m" $1`
@noamross
noamross / put64.R
Last active Jun 14, 2018
Simple R object to base64 conversion. Free to a good home in your R package! If you put it in your package, let me know 🙂
View put64.R
# Copyright 2018 Noam Ross
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
View hrbrfear.R
library(rtweet) #rtweet API creds should already be set up
library(dplyr)
library(ggplot2)
library(hrbrthemes)
library(tidytext)
library(lubridate)
hbt <- get_timeline("hrbrmstr", n=3200)
hbt2 <- hbt %>%
@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 / get_bat_wiki_pages.R
Last active Apr 1, 2018
Get the content of all bat Wikipedia pages
View get_bat_wiki_pages.R
library(tidyverse)
library(xml2)
library(rvest)
library(WikipediR)
library(urltools)
# Get all speceies-level page titles from the Wikipedia list of bats
bat_titles <- read_html("https://en.wikipedia.org/wiki/List_of_bats") %>%
html_nodes(xpath="//ul/li[contains(., 'Genus')]/ul/li/a[starts-with(@href, '/wiki/')]") %>%
xml_attr("href") %>%
@noamross
noamross / ropensci_editor_workloads.R
Last active Apr 1, 2018
Checking editor workloads for rOpenSci onboarding
View ropensci_editor_workloads.R
library(tidyverse)
library(gh)
library(lubridate)
issues <- gh("/repos/ropensci/onboarding/issues?state=all&labels=package", .limit=1000)
edits = map_df(issues,
~data_frame(url = .$html_url,
editor = .$assignee$login %||% NA_character_,
opened = as.Date(.$created_at))) %>%
View pandoc-newpage-filter.R
#!/usr/bin/env Rscript
json_in <- file('stdin', 'r')
lat_newp <- '{"t":"RawBlock","c":["latex","\\\\newpage"]}'
doc_newp <- '{"t":"RawBlock","c":["openxml","<w:p><w:r><w:br w:type=\\"page\\"/></w:r></w:p>"]}'
ast <- paste(readLines(json_in, warn=FALSE), collapse="\n")
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")
View catch_per_unit_effort.R
# Noam's take on Bob's lobseter plot
library(stringi)
library(pdftools)
library(hrbrthemes) #devtools::install_github("hrbrmstr/hrbrthemes"); hrbrthemes::import_roboto_condensed()
library(tidyverse)
# A different file provided by the state includes fishing effort
lobster_tbl <- "https://www.maine.gov/dmr/commercial-fishing/landings/documents/lobster.table.pdf"
lobster_tbl_fil <- basename(lobster_tbl)