Skip to content

Instantly share code, notes, and snippets.

View jhollist's full-sized avatar

Jeffrey W Hollister jhollist

View GitHub Profile
@jhollist
jhollist / get_nars.R
Last active January 26, 2017 18:12
R script to scrape US EPA NARS data and metadata
#Script to scrape NARS website
library(rvest)
library(dplyr)
nars <- read_html("https://www.epa.gov/national-aquatic-resource-surveys/data-national-aquatic-resource-surveys")
links <- nars %>%
html_nodes(".file-link, a") %>%
html_attr("href") %>%
tbl_df() %>%
filter(grepl("files",value)) %>%
> devtools::test()
Loading tidytext
Testing tidytext
Corpus tidiers: ..
dictionary tidiers:
LDA tidiers: .................................
Counting pairs: W.......W..W..WW...
Sparse casters: ................1
Sparse tidiers: ......
tf-idf calculation: ...........
@jhollist
jhollist / beamer_two_col.Rmd
Created February 3, 2016 18:51
This .Rmd shows how to use two (or more) columns in a Beamer Presentation from RStudio
---
title: "Untitled"
author: "Jeff W. Hollister"
date: "2/2/2016"
output: beamer_presentation
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(shiny)
library(dplyr)
library(DT)
dat<-data.frame(letters=c(rep("A",15),rep("B",5),rep("C",5)))
server<-shinyServer(function(input, output) {
#Returns filtered data
output$dat_false <- renderDataTable(dat,filter = "top",server = FALSE)
#Returns just the currently (?) visible values in the mainPanel
@jhollist
jhollist / sp_spocc_extract.R
Created March 31, 2015 20:25
Pass complex sp polygon to spocc
devtools::install_github("jhollist/quickmapr")
devtools::install_github("ropensci/spocc")
install.packages("rgeos")
library("quickmapr")
library("spocc")
library("rgeos")
library("magrittr")
data(lake)
## sp bbox to poly
@jhollist
jhollist / spocc_error_gist.R
Created March 28, 2015 16:05
Error when more complex sp passed to spocc
devtools::install_github('jhollist/quickmapr')
devtools::install_github('ropensci/spocc')
install.packages('rgeos')
library("quickmapr")
library("spocc")
library("rgeos")
data(lake)
## sp bbox to poly
bbox_to_sp <- function(sp) {
@jhollist
jhollist / buff_prob.R
Last active August 29, 2015 14:16
R script showing problem with turf.js buffers at smaller distances
#load libraries
library(jsonlite)
library(geojsonio)
library(sp)
library(lawn)
library(rgeos)
#create pt
pt<-minify('{
"type": "Feature",
@jhollist
jhollist / extract_spatial.R
Created October 14, 2014 17:09
function to interactively select and extract features from an `SpatialPolygons` or `SpatialPoints` object
extract_spatial<-function(in_spatial,over_poly=NULL,plot_result=FALSE){
plot(in_spatial)
message("Select at least 3 points to define the extent")
coords<-locator() %>%
data.frame()
poly<-rbind(coords,coords[1,]) %>%
Polygon() %>% list() %>%
Polygons(ID=1) %>% list() %>%
SpatialPolygons(proj4string=CRS(proj4string(in_spatial)))
idx<-over(poly,in_spatial,returnList=TRUE) %>% unlist()
@jhollist
jhollist / word_count.R
Created October 9, 2014 20:10
An R function to count words of an input text file. Built and tested on an Rmd without any R code in it.
word_count<-function(txt_doc){
con<-file(txt_doc, "r", blocking=FALSE)
x<-readLines(con)
#Remove YAML front matter on Rmd
if(length(grep("---",x))>0){x<-x[-seq(1,max(grep("---",x)))]}
wrds<-0
for(line in x){
#Removes non character and splits
split_line<-strsplit(gsub("[^[:alnum:] ]", "", line), " +")[[1]]
#Removes empty string
@jhollist
jhollist / yamlBug.Rmd
Last active August 29, 2015 14:06
Example problem with RStudio editor and collapsing yaml front matter
---
name: bob
title: example collapse bug
date: today
---
```{r}
#test of the collapse
```