library(taxizedb)
## Registered S3 method overwritten by 'hoardr':
## method from
## print.cache_info httr
# Convert degrees to radians | |
deg2rad <- function(deg) return(deg*pi/180) | |
# Calculates the geodesic distance between two points specified by | |
# radian latitude/longitude using the Haversine formula | |
# Ouputs distance between sites 1 and 2 as meters | |
gcd.hf <- function(long1, lat1, long2, lat2) { | |
R <- 6371 # Earth mean radius [km] | |
delta.long <- (long2 - long1) | |
delta.lat <- (lat2 - lat1) |
# 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", |
library(taxizedb)
## Registered S3 method overwritten by 'hoardr':
## method from
## print.cache_info httr
## ------------------------------------------------------------------------ | |
pop <- function(x, y) x[!y == names(x)] | |
## ------------------------------------------------------------------------ | |
if (!requireNamespace("xml2", quietly = TRUE)) { | |
install.packages("xml2") | |
} | |
if (!requireNamespace("dplyr", quietly = TRUE)) { | |
install.packages("dplyr") | |
} |
# Define the function | |
loghistplot <- function(data) { | |
require(ggplot2); require(gridExtra) # load packages | |
names(data) <- c('x','y') # rename columns | |
# get min and max axis values | |
min_x <- min(data$x) | |
max_x <- max(data$x) |
# process: | |
# - make a new branch: git checkout -b some-branch | |
# - run this script: Rscript path/to/package_strip_urls.R | |
# - update manual files and make sure package passes check | |
# - submit to cran | |
# - after accepted on cran - delete some-branch | |
have_pkg <- function(pkg) { | |
if (!requireNamespace(pkg, quietly = TRUE)) stop("need package ", pkg) | |
} |
#' Split up a vector into equal sized chunks | |
#' | |
#' @param input An input vector. | |
#' @param by The length of the resulting vectors. | |
#' @examples | |
#' vec <- c("a","b","d","e","f","g","h") | |
#' slice(vec, 3) | |
slice <- function(input, by=2){ | |
starts <- seq(1,length(input),by) | |
tt <- lapply(starts, function(y) input[y:(y+(by-1))]) |