Skip to content

Instantly share code, notes, and snippets.

@sckott
sckott / ggplot2SEM.R
Created May 1, 2012 05:23 — forked from emhart/ggplot2SEM.R
ggplot2 SEM model example
require(ggplot2); require(gridExtra)
###Generate box coords
###A function to generat a blank box for use with geom_path()
box_coords <- function(x,y,size){
b.x <- c(rep(x,2) - (size[1] / 2),rep(x,2) + (size[1] / 2))
b.x[5] <- b.x[1]
b.y <- c(y-(size[2] / 2),rep(y,2)+(size[2] / 2),y-(size[2] / 2))
b.y[5] <- b.y[1]
rmat <- data.frame(cbind(b.x,b.y))
@sckott
sckott / is.invasive.R
Created November 26, 2012 17:02 — forked from ibartomeus/is.invasive.R
This function check which species (both plants and animals) are considered "invaders" somewhere in the world.
is.invasive()
##Description##
#This function check which species (both plants and animals) are considered "invaders" somewhere in the
# world. For that end, it checks GISD (http://www.issg.org/database/welcome/) and returns a value, either
#"Not invasive" or the brief description presented in GISD. Note that the webpage contains more
#information. Also note that the function won't tell you if it's exotic in your area, a lot of exotic
#species are not considered invaders (yet). As expected, the function is as good as the database is, which
#I find quite reliable and well maintained. The database is also able to recognize a lot (but not all) of
@sckott
sckott / prepdata.R
Created December 10, 2012 22:58 — forked from emhart/server.R
rOpenSci rgbif shiny app test
splist <- c("Accipiter erythronemius", "Junco hyemalis", "Aix sponsa", "Haliaeetus leucocephalus",
"Corvus corone", "Threskiornis molucca", "Merops malimbicus")
out <- lapply(splist, function(x) occurrencelist(x, coordinatestatus=T, maxresults=500))
names(out) <- splist
setwd("~/ShinyApps/rgbif2")
save(out, file="speciesdata.rda")
@sckott
sckott / server.r
Last active December 18, 2015 03:39 — forked from ramnathv/server.r
require(shiny)
require(rCharts)
shinyServer(function(input, output){
output$chart <- renderMap({
require(rCharts)
map3 <- Leaflet$new()
map3$setView(c(51.505, -0.09), zoom = 13)
map3$tileLayer(provider = input$provider, urlTemplate = NULL)
map3$marker(c(51.5, -0.09), bindPopup = "<p> Hi. I am a popup </p>")
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sinon.js fakeServer demo</title>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/sinon.js/1.7.3/sinon-min.js"></script>
<script src="sinon-fake-server.js"></script>
</head>
<body>
@sckott
sckott / geo_json.R
Last active August 29, 2015 14:08 — forked from ateucher/geo_json.R
devtools::install_github("ropensci/togeojson@reworkapi")
library('togeojson')
library('maps')
data(us.cities)
to_geo_json(us.cities[1:2,], lat='lat', lon='long')
to_geojson(us.cities[1:2,], lat='lat', lon='long')
library(dplyr); library(httr); library(rvest)
addr <- "Big Ben"
GET("http://maps.google.com/maps/api/geocode/xml",
query = list(address = addr)) %>%
content() %>%
html_nodes(xpath = "//location//lat | //location//lng") %>%
html_text() %>%
setNames(c("lng", "lat"))
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
@sckott
sckott / body.R
Last active March 1, 2016 19:25 — forked from jeroen/body.R
Post data with GET
library(curl)
h <- new_handle()
handle_setform(h, limit = "3")
handle_setopt(h, customrequest = "POST")
handle_setheaders(h,
"X-HTTP-Method-Override" = "GET"
)
req <- curl_fetch_memory("http://data.techno-science.ca/api/3/action/package_list", handle = h)
jsonlite::fromJSON(rawToChar(req$content))$result
@sckott
sckott / clean_species.R
Last active October 5, 2021 14:19 — forked from ibartomeus/clean_species
Cleaning species taxonomy using taxize. I want to correct synonyms and typo's and drop incomplete cases.
# I have >1000 bees to check its name, so I want to automatize taxize for
# fixing misspellings when possible
# updating synonims to accepted names
# keeping ONLY accepted species (full resolved)
# As taxize has many functions I may be not being ptimal, commenets wellcomed.
# If you only want to use the function skip to the end,
# where I placed a wrap up function.
#example: good, synomin, typo, unexisting, genus only.
species <- c("Osmia rufa", "Osmia bicornis", "Osmia ruffa",