## ----setup, include = FALSE---------------------------------------------------
require(knitr)
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "../man/figures/README-"
)
opts_knit$set(message=FALSE, warnings=FALSE,error=FALSE,include=FALSE) 

## ----echo=FALSE, include=FALSE------------------------------------------------
library(stacomiR)


## ---- eval=FALSE--------------------------------------------------------------
#  # get the package from CRAN
#  install.packages("stacomiR")
#  # get the development version
#  install.packages("stacomiR", repos="http://R-Forge.R-project.org")

## ---- eval=FALSE--------------------------------------------------------------
#  stacomi()

## ---- eval=FALSE--------------------------------------------------------------
#  stacomi(gr_interface = FALSE, login_window = TRUE, database_expected = TRUE)

## ---- eval=TRUE, echo=TRUE----------------------------------------------------
## launches the application in the command line without connection to the database
stacomi(gr_interface=FALSE,login_window=FALSE,database_expected=FALSE) 

## ----eval=FALSE,echo=TRUE-----------------------------------------------------
#     stacomi(gr_interface=FALSE,
#  	  login_window=FALSE,
#  	  database_expected=TRUE)	
#    r_mig_mult=new("report_mig_mult")
#    r_mig_mult=choice_c(r_mig_mult,
#  	  dc=c(5,6,12),
#  	  taxa=c("Anguilla anguilla"),
#  	  stage=c("AGG","AGJ","CIV"),
#        datedebut="2011-01-01",
#        datefin="2011-12-31")
#    r_mig_mult<-charge(r_mig_mult)
#    # launching charge will also load classes associated with the report
#    # e.g. report_ope, report_df, report_dc
#    r_mig_mult<-connect(r_mig_mult)
#    # calculations
#    r_mig_mult<-calcule(r_mig_mult,silent=TRUE)

## ----rmmstd,eval=TRUE,echo=TRUE,message=FALSE,fig.height=6,fig.with=8---------
# Without a connection at the database we can launch these lines to generate the graph
# To obtain titles in french use Sys.setenv(LANG = "fr")
stacomi(gr_interface=FALSE,
	login_window=FALSE,
	database_expected=FALSE)	
data("r_mig_mult")
data("r_mig_mult_ope")
assign("report_ope",r_mig_mult_ope,envir=envir_stacomi)
data("r_mig_mult_df")
assign("report_df",r_mig_mult_df,envir=envir_stacomi)
data("r_mig_mult_dc")
assign("report_dc",r_mig_mult_dc,envir=envir_stacomi)
r_mig_mult<-calcule(r_mig_mult,silent=TRUE) 

# To avoid call to dev.new() which creates a device per stage, DC, taxa, we simplify 
# the object as dev.new() causes knitr to crash:
r_mig_mult@taxa@data<- r_mig_mult@taxa@data[1,]
r_mig_mult@stage@data<-r_mig_mult@stage@data[3,]
r_mig_mult@dc@dc_selectionne<-r_mig_mult@dc@dc_selectionne[3]

plot(r_mig_mult,plot.type="standard",silent=TRUE)


## ----rmmmult,eval=TRUE,echo=TRUE,fig.height = 4, fig.width = 6----------------

  plot(r_mig_mult,plot.type="multiple",silent=TRUE)

## ----silver,eval=TRUE,echo=TRUE,message=FALSE,warning=FALSE,fig.height = 4, fig.width = 6,fig.keep="all"----
require(stacomiR)
data("coef_durif")
# load a dataset of class report_silver_eel with data slot already prepared
# here is an example of output 
data("r_silver")
r_silver <- calcule(r_silver)
plot(r_silver, plot.type=3)
#######################################
# To use the function fun_stage_durif manually
# create a matrix with columns BL","W","Dv","Dh","FL"
#############################################
# here it is extracted from the data at hand
silver_eel<-as.matrix(r_silver@calcdata[[1]][,c("BL","W","Dv","Dh","FL")])
head(silver_eel) # to see the first lines
stage <- fun_stage_durif(silver_eel) # apply the function to the matrix
stage[1:10] # look at the first 10 elements in vector silver

