Skip to content

Instantly share code, notes, and snippets.

View jhollist's full-sized avatar

Jeffrey W Hollister jhollist

View GitHub Profile
library(USAboundaries)
library(sf)
library(dplyr)
library(elevatr)
library(raster)
# Get map of lower 48 states
usa_l48 <- us_boundaries() %>%
filter(state_abbr != "HI" &
state_abbr != "AK" &
@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 / iterate_waters.R
Created October 25, 2021 15:14
Example code for using a dataframe to access USEPA WATERS API. Shows two iteration examples: purrr and for loop.
library(purrr)
library(jsonlite)
library(dplyr)
library(usethis)
# The Data.gov API requires a key and has a 1000 request/hour limit
# Get Key from https://api.data.gov/signup/
# Save key in r environ
usethis::edit_r_environ()
# Add DATAGOV_KEY=YOURKEYGOESHERE to the file. Save and restart R