This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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", |
OlderNewer