Skip to content

Instantly share code, notes, and snippets.

View jhollist's full-sized avatar

Jeffrey W Hollister jhollist

View GitHub Profile
@jhollist
jhollist / example.Rmd
Created September 12, 2014 16:52
Example of .Rmd, with YAML trying to interpret code and objects set later in document
---
title: 'How do I interpret R code in YAML?'
author: Jeff Hollister
output:
pdf_document:
fig_caption: yes
keep_tex: yes
number_sections: yes
html_document: null
word_document: null
@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
```
@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 / 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 / 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 / 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
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 / peerjReivewForm.md
Last active December 31, 2015 04:09
This gist is simply a Markdown for PeerJ Reviews. As I do most of my writing in markdown, I wanted a template with the review categories and explanations in a handy location. This did the trick

Title of Paper

Authors

Basic Reporting

@jhollist
jhollist / census.md
Last active December 31, 2015 06:29
Example using census api

Example using R and the Census API to get pop for all 50 states

First step is to install httr

install.packages("httr")
library(httr)
> 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: ...........