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
get_ord_dataframe <- function(lines, linestart){ | |
header_line <- strsplit(lines[linestart], split="\t")[[1]] | |
num_rows = as.numeric(header_line[2]) | |
num_cols = as.numeric(header_line[3]) | |
if (num_rows == 0){return(data.frame())} | |
data <- strsplit(lines[(linestart+1):(linestart+num_rows)], split="\t") | |
names <- unlist(lapply(data, function(x) x[1])) | |
coords <- lapply(data, function(x) strsplit(x[2:(2+num_cols-1)], split="\t")) | |
coords <- data.frame(matrix(unlist(coords), nrow=length(coords), byrow=T), stringsAsFactors=FALSE) |
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
# Stolen from http://stackoverflow.com/a/12041779/914024 | |
gglegend <- function(x){ | |
tmp <- ggplot_gtable(ggplot_build(x)) | |
leg <- which(sapply(tmp$grobs, function(y) y$name) == "guide-box") | |
tmp$grobs[[leg]] | |
} |
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
# Libraries | |
library(MoreTreeTools) # package in dev, install via github: https://github.com/DomBennett/MoreTreeTools | |
library(doMC) # use doSNOW if using Windows | |
# find out how many cores you have | |
n <- detectCores() | |
# set-up | |
registerDoMC(cores=n) | |
# example tree | |
tree <- rtree(1000) | |
# find all internal nodes in tree |
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(maptools) | |
library(rgdal) | |
library(rgeos) | |
setwd("~/type1") | |
species <- 'speciesX1' | |
list_shp <- list.files(path=species, pattern="*.shp", full.names = TRUE, | |
recursive = TRUE, include.dirs = FALSE) | |
shp_objects <- lapply(list_shp, function(x) {readOGR(dsn=x, | |
layer=ogrListLayers(x))}) |