This file contains 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
# first define a function that downloads and loads baad from | |
# Ecological archives | |
load_baad <- function(filename = "downloads/baad_data.zip") { | |
path <- dirname(filename) | |
# download | |
if(!file.exists(filename)){ | |
dir.create(path, showWarnings = FALSE, recursive = TRUE) |
This file contains 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(xlsx) | |
library(smatr) | |
# get data, from publication Wright et al 2004. DOI: [10.1038/nature02403](http://doi.org/10.1038/nature02403) | |
download.file("http://www.nature.com/nature/journal/v428/n6985/extref/nature02403-s2.xls", "wright-2004.xls") | |
dat.Wright <- read.xlsx2("wright-2004.xls", sheetIndex=1, startRow=11, stringsAsFactors=FALSE, check.names=TRUE) | |
## Clean data | |
dat.Wright <- dat.Wright[names(dat.Wright) != " "] # Drop blank columns | |
for(v in c("log.LMA","log.LL")) |
This file contains 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
spp_code <- function(species_names){ | |
sapply(strsplit(species_names, " "), function(x) tolower(paste0(substr(x[1], 1,3), substr(x[2], 1,3)))) | |
} |
This file contains 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
csv_metadata <- function(filename){ | |
data <- read.csv(filename, stringsAsFactors=FALSE, fill=TRUE, header=TRUE, check.names = FALSE) | |
write.csv(data.frame(variable=names(data), units="",description="", notes=""), quote=TRUE, row.names=FALSE, | |
file = file.path(dirname(filename), paste0("metadata_",basename(filename)))) | |
} |
This file contains 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("RSQLite") | |
# connect to zotero database | |
pathToZotero <- "~/Zotero" # change this for your setup | |
m <- dbDriver("SQLite") | |
con <- dbConnect(m, file.path(pathToZotero, "zotero.sqlite")) | |
# extract list of journals |
This file contains 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
##' Modifies 'data' by adding new values supplied in newDataFileName | |
##' | |
##' newDataFileName is expected to have columns | |
##' c(lookupVariable,lookupValue,newVariable,newValue,source) | |
##' | |
##' Within the column 'newVariable', replace values that | |
##' match 'lookupValue' within column 'lookupVariable' with the value | |
##' newValue'. If 'lookupVariable' is NA, then replace *all* elements | |
##' of 'newVariable' with the value 'newValue'. | |
##' |