Skip to content

Commit

Permalink
Added the as.alienData function with help file written in roxygen2 (#2)
Browse files Browse the repository at this point in the history
* Added the as.alienData function with help file written in roxygen2

* CamelCase functions

* restore Bartomeus data file in R/

* Fixing issue with weight_sd and weight_mean functions

* removin weight_mean and weigthed_sd, already present in stats - close  #17

* Rebuild package and add new clean target in makefile

* fixinx syntax issues

* code review; fix minor issues/syntax errors

* Set mandatory idObs object in as.alienData() #21

* cleaning up data format

* removing ressourceConsumer matrix

* Details on roxygen documentation

* Add data consistency among interacPair and idObs #21

* set build interac matrix #21

* Add interacSp and interacInd from interacPair

* finish to reference interacSp and interacInd with idObs #21

* check consistency among traitSp and traitInd with idObs #21

* imp. coOcc methods: inferred or not; last checks on out objects; make sure coOcc rownames and colnames reffered to idObs

* make sure siteEnv are referenced in idObs #21

* build doc of as.alienData function

* Push last edits on as.alienData function

* set traitSp and traitInd as long format

* fixing functions errors

* Fixing last issue with res

* building docs; and close #21

* Add data and test it

* Add comments on as.alienData posible enhancements

* set Nacho's comments in issue #12

* set bartomeus in data folder

* init as.alienData test

* init test on integrity #18

* cover unit tests as.alienData() - issue #18

* add unit tests to data structure issue #18
  • Loading branch information
guiblanchet authored and SteveViss committed Feb 17, 2017
1 parent d4e1bf7 commit fa9b0a7
Show file tree
Hide file tree
Showing 10 changed files with 665 additions and 13 deletions.
9 changes: 2 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
rfun := $(wildcard R/*.R)
rman := $(wildcard man/)
rtes := $(wildcard tests/testthat/*.R)
rdm = README.Rmd
md = README.md
chk = record_updates.txt
rscr = pkg2date.R


all: $(md) $(chk)

$(md): $(rdm)
Rscript --no-site-file --no-init-file $(rscr) 0
all: $(chk)

$(chk): $(rfun) $(rtes) $(rman)
Rscript --no-site-file --no-init-file $(rscr) 1

clean:
rm -rf man/* NAMESPACES
rm -rf man/* NAMESPACE
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(as.alienData)
export(binomialToJags)
export(estNichPars)
export(extractBayesReg)
Expand All @@ -22,3 +23,4 @@ export(predNicheProb)
export(residualsNicheProb)
export(simTraitMatch)
importFrom(magrittr,"%>%")
importFrom(stats,sd)
531 changes: 531 additions & 0 deletions R/as.alienData.R

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions R/Bartomeus.R → R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
#' @docType data
#' @keywords datasets
#' @author Ignasi Bartomeus
#' @name Bartomeus
#' @usage data(Bartomeus)
#' @name bartomeus
#' @usage data(bartomeus)
#' @format A data frame with X variables
#' @export
# 'Bartomeus'
"bartomeus"
Binary file added data/bartomeus.rda
Binary file not shown.
55 changes: 55 additions & 0 deletions man/as.alienData.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions man/bartomeus.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg2date.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ if (!as.numeric(args[1])) {
decor()
## load the package
cat("##-- loading ........\n")
devtools::load_all(".")
devtools::load_all()
decor()
## document the package
cat("##-- documenting ....\n")
devtools::document(".")
devtools::document()
decor()
## testing the code
cat("##-- testing ........\n")
Expand Down
Binary file added tests/testthat/argsAlienData.RData
Binary file not shown.
42 changes: 42 additions & 0 deletions tests/testthat/test-alienData.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
context("alienData function")

load('./argsAlienData.RData')
out <- as.alienData(idObs=idObs,interactPair=interactPair,traitSp=traitSp,traitInd=traitInd,verbose=FALSE)

test_that("check data structure", {
expect_is(out, "alienData")
# Even if items from the list are NULL, all items have to be returned
expect_equal(names(out),c("idObs","interactSp","interactInd","coOcc","coAbund","siteEnv","traitSp","traitInd","phylo"))
})

test_that("check data integrity", {

# Generate fake data for idObs
len <- 3
sites <- sample(paste("site",letters[1:3],sep="_"),len,replace=TRUE) # 3 sites
sp <- paste0("sp",sample(1:len,len,replace=TRUE)) # 3 species
ind <- 1:len # 3 individus
idObs <- data.frame(idSite=sites,idTime=rep(NA,len),idSp=sp, idInd=ind,stringsAsFactors=FALSE)

interactPair <- data.frame(idTo=c("1","sp1"),idFrom=c("1","2"),strength=c(NA,NA),verbose=FALSE,stringsAsFactors=FALSE)
expect_error(as.alienData(idObs=idObs, interactPair=interactPair,verbose=FALSE),"'idTo' values belongs to 'idSp' and 'idInd' in 'idObs'. Interaction can't be at the species AND individual levels")

interactPair <- data.frame(idTo=c("1","2"),idFrom=c("sp1","2"),strength=c(NA,NA),verbose=FALSE,stringsAsFactors=FALSE)
expect_error(as.alienData(idObs=idObs, interactPair=interactPair,verbose=FALSE),"'idFrom' values belongs to 'idSp' and 'idInd' in 'idObs'. Interaction can't be at the species AND individual levels")

interactPair <- data.frame(idTo="sp4",idFrom="sp1",strength=NA,stringsAsFactors=FALSE)
expect_error(as.alienData(idObs=idObs, interactPair=interactPair,verbose=FALSE),"Some species ids in 'idTo' are not in 'idObs'")

interactPair <- data.frame(idTo="4",idFrom="1",strength=NA,stringsAsFactors=FALSE)
expect_error(as.alienData(idObs=idObs, interactPair=interactPair,verbose=FALSE),"Some individus ids in 'idTo' are not in 'idObs'")

interactPair <- data.frame(idTo="sp1",idFrom="sp4",strength=NA,stringsAsFactors=FALSE)
expect_error(as.alienData(idObs=idObs, interactPair=interactPair,verbose=FALSE),"Some species ids in 'idFrom' are not in 'idObs'")

interactPair <- data.frame(idTo="1",idFrom="4",strength=NA,stringsAsFactors=FALSE)
expect_error(as.alienData(idObs=idObs, interactPair=interactPair,verbose=FALSE),"Some individus ids in 'idFrom' are not in 'idObs'")

interactPair <- data.frame(idTo=c("2","2","3"),idFrom=c("2","2","2"),strength=c(NA,NA,NA),verbose=FALSE,stringsAsFactors=FALSE)
expect_error(as.alienData(idObs=idObs, interactPair=interactPair,verbose=FALSE),"Some 'idFrom' and 'idTo' are duplicated")

})

0 comments on commit fa9b0a7

Please sign in to comment.