Commit 6438bbab authored by Daniel Falster's avatar Daniel Falster
Browse files

Fix package loading function, needs character.only =TRUE for library function to work in loop'

No related merge requests found
Showing with 18 additions and 22 deletions
+18 -22
...@@ -6,10 +6,9 @@ ...@@ -6,10 +6,9 @@
################ use AccSpeciesName because not author name ################ use AccSpeciesName because not author name
source("../format.data/try.fun.R") source("../format.data/try.fun.R")
library(MASS)
library(doParallel) out.dir <- "../../output/formatted/TRY"
library(mvoutlier) dir.create(out.dir, recursive=TRUE,showWarnings=FALSE)
dir.create("../../output/formatted/TRY", recursive=TRUE,showWarnings=FALSE)
## read TRY data ## read TRY data
TRY.DATA <- read.table("../../data/raw/TRY/TRY_Proposal_177_DataRelease_2013_04_01.txt", TRY.DATA <- read.table("../../data/raw/TRY/TRY_Proposal_177_DataRelease_2013_04_01.txt",
...@@ -51,7 +50,7 @@ TRY.DATA.FORMATED <- foreach(ObservationID.t = unique(TRY.DATA$ObservationID), . ...@@ -51,7 +50,7 @@ TRY.DATA.FORMATED <- foreach(ObservationID.t = unique(TRY.DATA$ObservationID), .
## head(TRY.DATA.FORMATED) dim(TRY.DATA.FORMATED) ## head(TRY.DATA.FORMATED) dim(TRY.DATA.FORMATED)
saveRDS(TRY.DATA.FORMATED, file = "../../data/formatted/TRY/TRY.DATA.FORMATED.rds") saveRDS(TRY.DATA.FORMATED, file = file.path(out.dir, "TRY.DATA.FORMATED.rds"))
#### TODO MODIFY THE FUNCTION TO KEEP TRAITS SD AND INCLUDE IT LATER ON #### TODO MODIFY THE FUNCTION TO KEEP TRAITS SD AND INCLUDE IT LATER ON
...@@ -65,8 +64,7 @@ traits <- c("StdValue.Leaf.nitrogen..N..content.per.dry.mass", "StdValue.Seed.ma ...@@ -65,8 +64,7 @@ traits <- c("StdValue.Leaf.nitrogen..N..content.per.dry.mass", "StdValue.Seed.ma
data.TRY.std <- subset(TRY.DATA.FORMATED,select=c("ObservationID","AccSpeciesName","TF.exp.data","Reference","Sun.vers..shade.leaf.qualifier",traits)) data.TRY.std <- subset(TRY.DATA.FORMATED,select=c("ObservationID","AccSpeciesName","TF.exp.data","Reference","Sun.vers..shade.leaf.qualifier",traits))
names(data.TRY.std) <- c("obs.id","Latin_name","TF.exp.data","Reference","Sun.vs.shade.leaf","Leaf.N", "Seed.mass", "SLA", "Wood.density","height") names(data.TRY.std) <- c("obs.id","Latin_name","TF.exp.data","Reference","Sun.vs.shade.leaf","Leaf.N", "Seed.mass", "SLA", "Wood.density","height")
saveRDS(data.TRY.std,file="../../output/formatted/TRY/data.TRY.std.rds") saveRDS(data.TRY.std,file= file.path(out.dir, "data.TRY.std.rds"))
##################################################################### #####################################################################
...@@ -151,15 +149,12 @@ names(sd.vec.genus) <- c("sdlog10.gs.Nmass", "sdlog10.gs.Seed.Mass", "sdlog10.gs ...@@ -151,15 +149,12 @@ names(sd.vec.genus) <- c("sdlog10.gs.Nmass", "sdlog10.gs.Seed.Mass", "sdlog10.gs
"sdlog10.gs.WD", "sdlog10.gs.Height") "sdlog10.gs.WD", "sdlog10.gs.Height")
## save mean species and genus sd ## save mean species and genus sd
saveRDS(sd.vec.sp, file = "../../data/formatted/TRY/sd.vec.sp.rds") saveRDS(sd.vec.sp, file = file.path(out.dir, "sd.vec.sp.rds"))
saveRDS(sd.vec.genus, file = "../../data/formatted/TRY/sd.vec.genus.rds") saveRDS(sd.vec.genus, file = file.path(out.dir, "sd.vec.genus.rds"))
### plot sd to show mark ### plot sd to show mark
pdf("../../figs/sd.traits.pdf") pdf(file.path(out.dir, "sd.traits.pdf"))
r <- barplot(sd.vec.sp, names.arg = c("Leaf.N", "SM", "SLA", "WD", "Vessel", "LL"), r <- barplot(sd.vec.sp, names.arg = c("Leaf.N", "SM", "SLA", "WD", "Vessel", "LL"),
las = 2, ylim = c(0, 0.9), ylab = "sd log10") las = 2, ylim = c(0, 0.9), ylab = "sd log10")
points(r[, 1], sd.vec.genus, col = "red", pch = 16, cex = 2) points(r[, 1], sd.vec.genus, col = "red", pch = 16, cex = 2)
......
...@@ -2,10 +2,11 @@ ...@@ -2,10 +2,11 @@
# CHECK PACKGES are install and load # CHECK PACKGES are install and load
check_packages <- function(packages=c("data.table", "dismo", "doParallel", "foreign", "knitr", "maptools", "markdown", "MASS", "mvoutlier", "pander", "quantreg", "RColorBrewer", "reshape", "rgdal", "rjson", "rworldmap", "sp")){ check_packages <- function(packages=c("data.table", "dismo", "doParallel", "foreign", "knitr", "maptools", "markdown", "MASS", "mvoutlier", "pander", "quantreg", "RColorBrewer", "reshape", "rgdal", "rjson", "rworldmap", "sp")){
#install if needed #install if needed
new.packages <- packages[!(packages %in% installed.packages()[,"Package"])] new.packages <- packages[!(packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages) if(length(new.packages)) install.packages(new.packages)
#load #load
lappply(packages, library, quietly=TRUE) for(p in packages)
library(p, quietly=TRUE, character.only =TRUE)
} }
...@@ -10,7 +10,7 @@ Kunstler *et al.* (2012) "Competitive interactions between forest trees are driv ...@@ -10,7 +10,7 @@ Kunstler *et al.* (2012) "Competitive interactions between forest trees are driv
The repository has the following basic directories: The repository has the following basic directories:
- `data`: contains raw data and metadata. Treat this as read-only, i.e. do not save output from R scripts here, these go in outputs. - `data`: contains raw data and meta data. Treat this as read-only, i.e. do not save output from R scripts here, these go in outputs.
- `R`: where all R code used in analysis is saved. The only exception is `*.Rmd` files used in creating some of the documents, which are stored in `docs` directory. - `R`: where all R code used in analysis is saved. The only exception is `*.Rmd` files used in creating some of the documents, which are stored in `docs` directory.
- `output`: a temporary directory that is used to hold all process data. Material in this directory is not tracked because it can be recreated from scripts. - `output`: a temporary directory that is used to hold all process data. Material in this directory is not tracked because it can be recreated from scripts.
- `docs`: contains documents developed for the project. - `docs`: contains documents developed for the project.
...@@ -19,16 +19,16 @@ Some specific folders of likely interest: ...@@ -19,16 +19,16 @@ Some specific folders of likely interest:
- `docs/meeting.agenda`: agenda for workshop - `docs/meeting.agenda`: agenda for workshop
- `docs/analysis.outline`: theoretical description of analysis - `docs/analysis.outline`: theoretical description of analysis
- `docs/analysis.pipeline`: outline of workflow (code, data etc). - `docs/analysis.pipeline`: outline of work flow (code, data etc).
- `data/raw`: Directory containing all the raw data from different sites. By default, this directory is not available. - `data/raw`: Directory containing all the raw data from different sites. By default, this directory is not available.
- `docs/metadata`: Contains infomration about the dataset from each site - `docs/metadata`: Contains information about the dataset from each site
- `ms`: eventual home for manuscript materials - `ms`: eventual home for manuscript materials
## Tools ## Tools
We are making use of the following tools: We are making use of the following tools:
- *R stats program* - [*R stats program*](http://www.r-project.org/), for all analyses
- A number R libraries. We have embedded a function in the code to load missing packages where possible (see `R/packages.R`) - A number R libraries. We have embedded a function in the code to load missing packages where possible (see `R/packages.R`)
- [*markdown*](http://daringfireball.net/projects/markdown/) - [*markdown*](http://daringfireball.net/projects/markdown/)
- The [*knitr*](http://cran.r-project.org/web/packages/knitr/index.html) package in R, for generating documents with R and markdown. For a n intro see [here](http://nicercode.github.io/guides/reports/) - The [*knitr*](http://cran.r-project.org/web/packages/knitr/index.html) package in R, for generating documents with R and markdown. For a n intro see [here](http://nicercode.github.io/guides/reports/)
...@@ -40,20 +40,20 @@ Documents are kept under version control using git, and stored on github. To acc ...@@ -40,20 +40,20 @@ Documents are kept under version control using git, and stored on github. To acc
1. Sign up to github and send your username to Georges so he can add you to the repository for this workshop, called `trait.competition.workshop` 1. Sign up to github and send your username to Georges so he can add you to the repository for this workshop, called `trait.competition.workshop`
2. Download repository via github software 2. Download repository via github software
- [Github for mac] (http://mac.github.com/) - [Github for mac](http://mac.github.com/)
- [Github for windows](http://windows.github.com/) - [Github for windows](http://windows.github.com/)
3. You also view the material online [here](https://github.com/kunstler/trait.competition.workshop) 3. You also view the material online [here](https://github.com/kunstler/trait.competition.workshop)
For an intro to git, see [http://nicercode.github.io/git/](http://nicercode.github.io/git/) For an intro to git, see [http://nicercode.github.io/git/](http://nicercode.github.io/git/)
Once downloaded, you can interact with the material via your github software, the shell, or [Rstudio](http://www.rstudio.com/), and R editor with built in git capabilities. Once downloaded, you can interact with the material via your github software, the shell, or [Rstudio](http://www.rstudio.com/) - an R editor with built in git capabilities.
## Key points for intro ## Key points for intro
- Intro to git and github - Intro to git and github
- version control - version control
- text files - text files
- setup: - set up:
- install github, rstudio - install github, rstudio
- R project - R project
- Ideal: run on anyone's computer, never use setwd() - Ideal: run on anyone's computer, never use setwd()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment