Permalink
Browse files

update README.md

  • Loading branch information...
valcu committed Mar 14, 2018
1 parent 61a8a7b commit fd2f29936ba0cb66653c95f936590c043a7c42a5
@@ -18,3 +18,4 @@ vignettes/*.html
vignettes/*.pdf
vignettes/*.png
/rangeMapper.sublime-workspace
/README.html
@@ -1,5 +1,5 @@
Package: rangeMapper
Version: 0.3-1
Version: 0.3-2
Authors@R: c(
person("Mihai", "Valcu", ,"valcu@orn.mpg.de", c("aut", "cre")),
person("James", "Dale", , "J.Dale@massey.ac.nz", "aut"),
@@ -59,3 +59,4 @@ Collate:
'utils-spatial.R'
'utils.R'
VignetteBuilder: knitr
Encoding: UTF-8
@@ -131,7 +131,7 @@ setMethod("processRanges",
st$sql = paste("ALTER TABLE metadata_ranges ADD COLUMN", st$cols, st$sqltypes)
# prepare metadata table
sapply(st$sql, dbGetQuery, conn = con)
sapply(st$sql, dbExecute, conn = con)
# save
dbWriteTable(con, rmo@METADATA_RANGES, rtr, append = TRUE, row.names = FALSE)
@@ -220,7 +220,7 @@ setMethod("processRanges",
st$sql = paste("ALTER TABLE metadata_ranges ADD COLUMN", st$cols, st$sqltypes)
# prepare metadata table
sapply(st$sql, dbGetQuery, conn = con)
sapply(st$sql, dbExecute, conn = con)
# save 1st range metadata
dbWriteTable(con, rmo@METADATA_RANGES, rtr1, append = TRUE, row.names = FALSE)
@@ -19,7 +19,7 @@ setMethod("rangeMapRemove",
for (i in 1:length(sql)) {
message("SQLITE:", sql[i])
dbGetQuery(object@CON , sql[i])
dbExecute(object@CON , sql[i])
}
}
})
@@ -19,9 +19,9 @@ setMethod("rangeMapSave",
if(!is.null(sset)) paste("WHERE", sset), "group by r.id")
# build table and index
dbGetQuery(object@CON, paste("CREATE TABLE" ,tableName, "(", object@ID, "INTEGER,",object@tableName, "NUMERIC) -- DDL:", richnessSQL))
dbGetQuery(object@CON,paste("CREATE INDEX", paste(object@tableName, object@ID, sep = "_") ,"ON", tableName, "(id)") )
dbGetQuery(object@CON, paste("INSERT INTO" ,tableName, richnessSQL) )
dbExecute(object@CON, paste("CREATE TABLE" ,tableName, "(", object@ID, "INTEGER,",object@tableName, "NUMERIC) -- DDL:", richnessSQL))
dbExecute(object@CON,paste("CREATE INDEX", paste(object@tableName, object@ID, sep = "_") ,"ON", tableName, "(id)") )
dbExecute(object@CON, paste("INSERT INTO" ,tableName, richnessSQL) )
return(dbtable.exists(object@CON, tableName))
@@ -61,9 +61,9 @@ setMethod("rangeMapSave",
sql = paste("SELECT id,", FUN ,"(", object@biotrait, ") as", object@biotrait, "from (",sql,") group by id")
# build table and index
dbGetQuery(object@CON, paste("CREATE TABLE",tableName, "(", object@ID, "INTEGER,",object@biotrait, "NUMERIC)"))
dbGetQuery(object@CON, paste("CREATE INDEX", paste(tableName, "id", sep = "_") , "ON", tableName, "(id)") )
dbGetQuery(object@CON, paste("INSERT INTO" ,tableName, sql) )
dbExecute(object@CON, paste("CREATE TABLE",tableName, "(", object@ID, "INTEGER,",object@biotrait, "NUMERIC)"))
dbExecute(object@CON, paste("CREATE INDEX", paste(tableName, "id", sep = "_") , "ON", tableName, "(id)") )
dbExecute(object@CON, paste("INSERT INTO" ,tableName, sql) )
return(dbtable.exists(object@CON, tableName))
@@ -81,7 +81,7 @@ setMethod("rangeMapSave",
# tableName
tableName = paste(object@MAP, object@tableName, sep = "")
# get data afer checking
# get data after checking
dl = .rangeMapSaveData (object)
if (inherits(cl, "cluster")){
@@ -98,8 +98,8 @@ setMethod("rangeMapSave",
row.names(X) = NULL
# build table and index
dbGetQuery(object@CON, paste("CREATE TABLE" ,tableName, "(", object@ID, "INTEGER,",object@biotrait, "NUMERIC)"))
dbGetQuery(object@CON, paste("CREATE INDEX", paste(tableName, "id", sep = "_") , "ON", tableName, "(id)") )
dbExecute(object@CON, paste("CREATE TABLE" ,tableName, "(", object@ID, "INTEGER,",object@biotrait, "NUMERIC)"))
dbExecute(object@CON, paste("CREATE INDEX", paste(tableName, "id", sep = "_") , "ON", tableName, "(id)") )
dbWriteTable(object@CON, tableName, X, row.names = FALSE, append = TRUE)
return(dbtable.exists(object@CON, tableName))
@@ -114,7 +114,7 @@ setMethod("rangeMapSave",
# tableName
tableName = paste(object@MAP, object@tableName, sep = "")
# get data afer checking
# get data after checking
dl = .rangeMapSaveData (object)
if (inherits(cl, "cluster")){
@@ -131,8 +131,8 @@ setMethod("rangeMapSave",
row.names(X) = NULL
# build table and index
dbGetQuery(object@CON, paste("CREATE TABLE" ,tableName, "(", object@ID, "INTEGER,",object@biotrait, "NUMERIC)"))
dbGetQuery(object@CON, paste("CREATE INDEX", paste(tableName, "id", sep = "_") , "ON", tableName, "(id)") )
dbExecute(object@CON, paste("CREATE TABLE" ,tableName, "(", object@ID, "INTEGER,",object@biotrait, "NUMERIC)"))
dbExecute(object@CON, paste("CREATE INDEX", paste(tableName, "id", sep = "_") , "ON", tableName, "(id)") )
dbWriteTable(object@CON, tableName, X, row.names = FALSE, append = TRUE)
dbtable.exists(object@CON, tableName)
@@ -184,8 +184,8 @@ setMethod("rangeMapImport",
# build table and index
message("Creating table and indexes...")
dbGetQuery(object@CON, paste("CREATE TABLE" ,tableName, "(", object@ID, "INTEGER,",object@tableName, "FLOAT)"))
dbGetQuery(object@CON, paste("CREATE INDEX", paste(tableName, "id", sep = "_") , "ON", tableName, "(id)") )
dbExecute(object@CON, paste("CREATE TABLE" ,tableName, "(", object@ID, "INTEGER,",object@tableName, "FLOAT)"))
dbExecute(object@CON, paste("CREATE INDEX", paste(tableName, "id", sep = "_") , "ON", tableName, "(id)") )
dbWriteTable(object@CON, tableName, o, row.names = FALSE, append = TRUE)
@@ -288,10 +288,10 @@ setMethod("rangeMapImport",
rangeMap.save <- function(CON, tableName, FUN, biotab, biotrait, subset = list(), path , overwrite = FALSE, cl, ...) {
if(overwrite & !missing(tableName))
try(dbGetQuery(CON, paste("DROP TABLE", paste("MAP", tableName, sep = "_"))), silent = TRUE)
try(dbExecute(CON, paste("DROP TABLE", paste("MAP", tableName, sep = "_"))), silent = TRUE)
if(overwrite & missing(tableName))
try(dbGetQuery(CON, "DROP TABLE MAP_species_richness"), silent = TRUE)
try(dbExecute(CON, "DROP TABLE MAP_species_richness"), silent = TRUE)
@@ -17,7 +17,7 @@ setMethod("bioSave",
res = dbWriteTable(object@CON ,tableName , d, row.names = FALSE)
if(res) {
dbGetQuery(object@CON,(paste("CREATE INDEX", paste(tableName, object@ID, sep = "_") , "ON", tableName , "(", object@ID ,")")) )
dbExecute(object@CON,(paste("CREATE INDEX", paste(tableName, object@ID, sep = "_") , "ON", tableName , "(", object@ID ,")")) )
message(paste("Table", object@tableName, "saved as a ", object@BIO, "table") )
}
}
@@ -40,7 +40,7 @@ setMethod("bioSave",
res = dbWriteTable(object@CON ,tableName , d, row.names = FALSE)
if(res) {
dbGetQuery(object@CON,(paste("CREATE INDEX", paste(tableName, object@ID, sep = "_") , "ON", tableName , "(", object@ID ,")")) )
dbExecute(object@CON,(paste("CREATE INDEX", paste(tableName, object@ID, sep = "_") , "ON", tableName , "(", object@ID ,")")) )
message(paste("Table", object@tableName, "saved as a ", object@BIO, "table") )
} else
message( paste("Error in saving", object@tableName) )
@@ -16,19 +16,19 @@ setMethod("rangeMapStart", signature = "rangeMapStart", definition = function(o
Queries = object@skeleton
db = unlist(Queries)
for (i in 1:length(db))
dbGetQuery(CON , db[i])
dbExecute(CON , db[i])
dbGetQuery(CON, verSql)
dbExecute(CON, verSql)
}
if(object@overwrite && file.exists) {
dropAll = dbGetQuery(CON, "select 'drop table if exists ' || name from sqlite_master where type = 'table';")
if(nrow(dropAll) == 0) dropAll = NULL else dropAll = dropAll[,1 ]
Queries = c(dropAll, "vacuum", object@skeleton )
db = unlist(Queries)
for (i in 1:length(db)) dbGetQuery(CON , db[i])
for (i in 1:length(db)) dbExecute(CON , db[i])
dbGetQuery(CON, verSql)
dbExecute(CON, verSql)
}
if(!object@overwrite && file.exists) stop(paste("File", object@file, "already exists!"))
BIN +109 KB (340%) README-1-1.png
Binary file not shown.
@@ -10,8 +10,8 @@ knitr::opts_chunk$set(
)
```
[![Travis-CI Build Status](https://travis-ci.org/valcu/rangeMapper.svg?branch=master)](https://travis-ci.org/valcu/rangeMapper)
[![Coverage Status](https://img.shields.io/codecov/c/github/valcu/rangeMapper/master.svg)](https://codecov.io/github/valcu/rangeMapper?branch=master)
[![Travis-CI Build Status](https://travis-ci.org/mpio-be/rangeMapper.svg?branch=master)](https://travis-ci.org/mpio-be/rangeMapper)
[![Coverage Status](https://img.shields.io/codecov/c/github/mpio-be/rangeMapper/master.svg)](https://codecov.io/github/mpio-be/rangeMapper?branch=master)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/rangeMapper)](http://cran.r-project.org/package=rangeMapper)
@@ -20,20 +20,30 @@ knitr::opts_chunk$set(
### _rangeMapper_ in a nutshell
```{r,echo=FALSE,results='hide', message=FALSE,warning=FALSE, fig.width=10, fig.height=5}
require(rangeMapper)
require(rangeMapper); require(magrittr)
require(ggplot2)
breding_ranges = rgdal::readOGR(system.file(package = "rangeMapper",
"extdata", "wrens", "vector_combined"), "wrens", verbose = FALSE)
require(rgdal)
breding_ranges = rgdal::readOGR(system.file(package = "rangeMapper", "extdata", "wrens", "vector_combined"), "wrens", verbose = FALSE)
breding_ranges = spTransform(breding_ranges, CRS('+proj=moll')) %>% rgeos::gBuffer(width = 0, byid = TRUE)
wrens_boundary = rgeos::gUnionCascaded(breding_ranges)
data(wrens)
d = subset(wrens, select = c('sci_name', 'body_mass', 'clutch_size') )
con = ramp("wrens.sqlite", gridSize = 1, spdf = breding_ranges, biotab = d, ID = "sci_name",
con = ramp("wrens.sqlite", gridSize = 150000, spdf = breding_ranges, biotab = d, ID = "sci_name",
FUN = "median", overwrite = TRUE)
```
* Datasets (i.e. maps) are retrieved from `sqlite` project files as objects inheriting from `SpatialPixels` or `data.table`. Maps can be plotted directly with `plot()`.
```{r,1, fig.cap="", echo=TRUE,results='hide', message=FALSE,warning=FALSE, fig.width=10, fig.height=5}
map = rangeMap.fetch(con, c('median_body_mass', 'median_clutch_size'), spatial = FALSE)
plot(map, boundary = wrens_boundary, ncol = 2)
plot(map, boundary = wrens_boundary, ncol = 2 , outlierDetector = function(x) extremevalues::getOutliersI(x)$limit)
```
* The link between the assemblage level (i.e. the raster cell) and the species level (i.e. the data behind the raster cell) is kept explicit at all stages of the project.
@@ -52,7 +62,7 @@ rangeMap.save(con, FUN = lmSlope, biotab = "life_history_traits",
### Installation
```R
devtools::install_github("valcu/rangeMapper") # development.
devtools::install_github("mpio-be/rangeMapper") # development.
install.packages("rangeMapper") # stable.
```
@@ -9,11 +9,12 @@ con = ramp("wrens.sqlite", gridSize = 10, spdf = breding_ranges, biotab = d, ID
test_that("rangeMap.save subsetting", {
rangeMap.save(con, biotab = "biotab", biotrait = "body_mass",
expect_true(
rangeMap.save(con, biotab = "biotab", biotrait = "body_mass",
tableName = "x", FUN = "avg",
list(MAP_species_richness = "species_richness >= 5",
BIO_biotab = "body_size > 15"
), overwrite = TRUE)
), overwrite = TRUE) )
})

0 comments on commit fd2f299

Please sign in to comment.