[Stacomir-commits] r188 - / pkg/stacomir pkg/stacomir/R pkg/stacomir/examples pkg/stacomir/examples/02_BilanMigration pkg/stacomir/inst/tests/testthat pkg/stacomir/man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Sep 1 21:39:15 CEST 2016


Author: briand
Date: 2016-09-01 21:39:15 +0200 (Thu, 01 Sep 2016)
New Revision: 188

Added:
   . Rinstignore
   pkg/stacomir/examples/02_BilanMigration/
   pkg/stacomir/examples/02_BilanMigration/Readme.md
   pkg/stacomir/examples/02_BilanMigration/bilanMigration_Arzal.R
   pkg/stacomir/inst/tests/testthat/test-02BilanMigration.R
   pkg/stacomir/man/calcule-BilanMigrationConditionEnv-method.Rd
Removed:
   pkg/stacomir/examples/00_BilanMigration/
Modified:
   pkg/stacomir/DESCRIPTION
   pkg/stacomir/NAMESPACE
   pkg/stacomir/R/BilanMigration.r
   pkg/stacomir/R/fn_EcritBilanJournalier.r
   pkg/stacomir/R/fn_EcritBilanMensuel.r
   pkg/stacomir/inst/tests/testthat/test-01BilanMigrationMult.R
   pkg/stacomir/man/BilanMigration-class.Rd
   pkg/stacomir/man/BilanMigrationInterAnnuelle-class.Rd
   pkg/stacomir/man/calcule-BilanMigration-method.Rd
   pkg/stacomir/man/fn_EcritBilanJournalier.Rd
   pkg/stacomir/man/fungraph.Rd
   pkg/stacomir/man/plot-BilanMigration-ANY-method.Rd
Log:
Tests for BilanMigration class, integration of fn_EcritBilanJournalier and fn_EcritBilanMensuel. Debug of these functions still to run....

Added: . Rinstignore
===================================================================
Modified: pkg/stacomir/DESCRIPTION
===================================================================
--- pkg/stacomir/DESCRIPTION	2016-09-01 18:46:49 UTC (rev 187)
+++ pkg/stacomir/DESCRIPTION	2016-09-01 19:39:15 UTC (rev 188)
@@ -10,6 +10,7 @@
     available in French English and Spanish.
 License: GPL (>= 2)
 Collate:
+    'BilanAnnuels.r'
     'utilitaires.r'
     'create_generic.r'
     'RefStationMesure.r'
@@ -35,7 +36,6 @@
     'Refparqual.r'
     'Refparquan.r'
     'BilanMigrationPar.r'
-    'BilanAnnuels.r'
     'Bilan_carlot.r'
     'RefCoe.r'
     'Bilan_poids_moyen.r'

Modified: pkg/stacomir/NAMESPACE
===================================================================
--- pkg/stacomir/NAMESPACE	2016-09-01 18:46:49 UTC (rev 187)
+++ pkg/stacomir/NAMESPACE	2016-09-01 19:39:15 UTC (rev 188)
@@ -1,6 +1,8 @@
 # Generated by roxygen2: do not edit by hand
 
 export(chargecsv)
+export(fn_EcritBilanJournalier)
+export(fn_EcritBilanMensuel)
 export(funBilanMigrationAnnuel)
 export(fun_bilanMigrationMult)
 export(fun_bilanMigrationMult_Overlaps)

Modified: pkg/stacomir/R/BilanMigration.r
===================================================================
--- pkg/stacomir/R/BilanMigration.r	2016-09-01 18:46:49 UTC (rev 187)
+++ pkg/stacomir/R/BilanMigration.r	2016-09-01 19:39:15 UTC (rev 188)
@@ -26,6 +26,7 @@
 #' \code{\linkS4class{BilanMigrationInterAnnuelle}}, 
 #' \code{\linkS4class{BilanMigrationPar}}
 #' @concept Bilan Object 
+#' @example examples/02_BilanMigration/bilanMigration_Arzal.R
 #' @export 
 setClass(Class="BilanMigration",
 		representation=
@@ -254,7 +255,7 @@
 			}
 		})
 
-#' Plots of various type for BilanMigration
+#' Plots of various type for BilanMigration, and performs writing to the database of daily values.
 #' 
 #' \itemize{
 #' 		\item{plot.type="standard"}{calls \code{\link{fungraph}} and \code{\link{fungraph_civelle}} functions to plot as many "bilanmigration"
@@ -262,9 +263,11 @@
 #' 		\item{plot.type="step"}{creates Cumulated graphs for BilanMigrationMult.  Data are summed per day for different dc taxa and stages}
 #' 		\item{plot.type="multiple"}{Method to overlay graphs for BilanMigrationMult (multiple dc/taxa/stage in the same plot)}
 #' }
+#' @note When plotting the "standard" plot, the user will be prompted to "write" the daily migration and monthly migration in the database.
+#' these entries are necessary to run the Interannual Migration class.
 #' @param x An object of class BilanMigrationMult
 #' @param y From the formals but missing
-#' @param plot.type One of "standard","step","multiple". Defaut to \code{standard} the standard BilanMigration with dc and operation displayed, can also be \code{step} or 
+#' @param plot.type One of "standard","step". Defaut to \code{standard} the standard BilanMigration with dc and operation displayed, can also be \code{step} or 
 #' \code{multiple} 
 #' @param ... Additional arguments, see \code{plot}, \code{plot.default} and \code{par}
 #' @author Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
@@ -340,6 +343,10 @@
 									silent)
 						}
 					} # end nrow(data)>0	
+					###########################################""
+					# Writes the daily bilan in the database
+					#########################################
+					fn_EcritBilanJournalier(bilanMigration)
 				} # end is.null(data)
 				
 				#§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§

Modified: pkg/stacomir/R/fn_EcritBilanJournalier.r
===================================================================
--- pkg/stacomir/R/fn_EcritBilanJournalier.r	2016-09-01 18:46:49 UTC (rev 187)
+++ pkg/stacomir/R/fn_EcritBilanJournalier.r	2016-09-01 19:39:15 UTC (rev 188)
@@ -1,11 +1,14 @@
 #' fn_EcritBilanJournier writes the daily migration in the
 #' t_bilanmigrationjournalier_bjo table
 #' 
+#' Daily values are needed to compare migrations from year to year, by the class \link{BilanMigrationInterAnnuelle-class}. They are added by
+#' the function fn_EcritBilanJournalier
 #' 
 #' @param bilanMigration an object of class \code{\linkS4class{BilanMigration}}
 #' @note the user is asked whether or not he wants to overwrite data, if no
 #' data are present in the database, the import is done anyway
 #' @author Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
+#' @export
 fn_EcritBilanJournalier<-function(bilanMigration){
 	# voir essai_table_bilanJournalier.sql pour le format du tableau
 	# je cherche les colonnes que je ne veux pas retenir

Modified: pkg/stacomir/R/fn_EcritBilanMensuel.r
===================================================================
--- pkg/stacomir/R/fn_EcritBilanMensuel.r	2016-09-01 18:46:49 UTC (rev 187)
+++ pkg/stacomir/R/fn_EcritBilanMensuel.r	2016-09-01 19:39:15 UTC (rev 188)
@@ -5,6 +5,7 @@
 #' 
 #' @param bilanMigration an object of class \code{\linkS4class{BilanMigration}}
 #' @param resum data frame with summary per month
+#' @export
 fn_EcritBilanMensuel<-function(bilanMigration,resum){
 	# voir essai_table_bilanmensuel.sql pour le format du tableau
 	t_bilanmigrationmensuel_bme=stacomirtools::killfactor(

Copied: pkg/stacomir/examples/02_BilanMigration/Readme.md (from rev 182, pkg/stacomir/examples/00_BilanMigration/Readme.md)
===================================================================
--- pkg/stacomir/examples/02_BilanMigration/Readme.md	                        (rev 0)
+++ pkg/stacomir/examples/02_BilanMigration/Readme.md	2016-09-01 19:39:15 UTC (rev 188)
@@ -0,0 +1,2 @@
+This examples demonstrates the use of the *BilanMigration* class. 
+It comes from the Arzal fishway and includes only one `dc`  `species`and `stage`. It is intended to work without the database installed.

Copied: pkg/stacomir/examples/02_BilanMigration/bilanMigration_Arzal.R (from rev 185, pkg/stacomir/examples/00_BilanMigration/bilanMigration_Arzal.R)
===================================================================
--- pkg/stacomir/examples/02_BilanMigration/bilanMigration_Arzal.R	                        (rev 0)
+++ pkg/stacomir/examples/02_BilanMigration/bilanMigration_Arzal.R	2016-09-01 19:39:15 UTC (rev 188)
@@ -0,0 +1,43 @@
+library(stacomiR)
+
+stacomi(gr_interface=FALSE,login_window=FALSE,pre_launch_test=FALSE) 
+## launches the application in the command line
+## here an example of loading
+## not run as the program is possibly not installed
+## this example generates the bM_Arzal dataset
+\dontrun{
+	stacomi(gr_interface=FALSE,
+			login_window=FALSE,
+			pre_launch_test=FALSE)	
+	bM_Arzal=new("BilanMigration")
+	bM_Arzal=choice_c(bM_Arzal,
+			dc=5,
+			taxons=c("Liza ramada"),
+			stades=c("IND"),
+			datedebut="2015-01-01",
+			datefin="2015-12-31")
+	bM_Arzal<-connect(bM_Arzal)
+}
+
+
+data("bM_Arzal")
+# use the following to get the raw data loaded by the connect method
+# not shown there as the database and program might not be installed
+
+#bM_Arzal<-connect(bM_Arzal)
+#str(bM_Arzal at data)
+# calculations
+bM_Arzal<-calcule(bM_Arzal)
+#Individual plot for all DC (standard), taxon and stage where data present
+#silent argument to stop all messages
+plot(bM_Arzal,plot.type="standard",silent=TRUE)
+
+#cumulated migration at the station (all stages and DC grouped)
+plot(bM_Arzal,plot.type="step")
+#some plots are a mixture of french and english
+#changing the reference table names to english should shift all to english.
+#same for spanish.
+# combined plot for ggplot2
+plot(bM_Arzal,plot.type="multiple")
+# data will be written in the data directory specified in the stacomi/calcmig.csv file
+summary(bM_Arzal)

Modified: pkg/stacomir/inst/tests/testthat/test-01BilanMigrationMult.R
===================================================================
--- pkg/stacomir/inst/tests/testthat/test-01BilanMigrationMult.R	2016-09-01 18:46:49 UTC (rev 187)
+++ pkg/stacomir/inst/tests/testthat/test-01BilanMigrationMult.R	2016-09-01 19:39:15 UTC (rev 188)
@@ -1,6 +1,3 @@
-# Author: cedric.briand
-###############################################################################
-
 context("BilanMigrationMult")
 test_that("Test an instance of bilanMigrationMult",{
 			require(stacomiR)

Added: pkg/stacomir/inst/tests/testthat/test-02BilanMigration.R
===================================================================
--- pkg/stacomir/inst/tests/testthat/test-02BilanMigration.R	                        (rev 0)
+++ pkg/stacomir/inst/tests/testthat/test-02BilanMigration.R	2016-09-01 19:39:15 UTC (rev 188)
@@ -0,0 +1,64 @@
+context("BilanMigration")
+test_that("Test an instance of bilanMigration",{
+			require(stacomiR)
+			stacomi(gr_interface=FALSE,login_window=FALSE,pre_launch_test=FALSE)
+			# overriding user schema to point to iav
+			baseODBC<-get("baseODBC",envir=envir_stacomi)
+			baseODBC[c(2,3)]<-rep("iav",2)
+			assign("baseODBC",baseODBC,envir_stacomi)
+			sch<-get("sch",envir=envir_stacomi) # "iav."
+			assign("sch","iav.",envir_stacomi)
+			
+			bilanMigration<-new("BilanMigration")
+			options(warn = 2)
+			bilanMigration<-choice_c(bilanMigration,
+					dc=c(6),
+					taxons=c("Anguilla anguilla"),
+					stades=c("AGJ"),
+					datedebut="2013-01-01",
+					datefin="2013-12-31")
+			options(warn = 0)
+			expect_s4_class(bilanMigration,
+					"BilanMigration")
+			rm("envir_stacomi",envir =.GlobalEnv)
+		})
+
+test_that("Test connect method",{
+			stacomi(gr_interface=FALSE,
+					login_window=FALSE,
+					pre_launch_test=FALSE)	
+			# overriding user schema
+			baseODBC<-get("baseODBC",envir=envir_stacomi)
+			baseODBC[c(2,3)]<-rep("iav",2)
+			assign("baseODBC",baseODBC,envir_stacomi)
+			sch<-get("sch",envir=envir_stacomi) # "iav."
+			assign("sch","iav.",envir_stacomi)
+	# this chunk is not launched from examples but loads the bM_Arzal dataset if connection works	
+			bM_Arzal=new("BilanMigration")
+			bM_Arzal=choice_c(bM_Arzal,
+					dc=5,
+					taxons=c("Liza ramada"),
+					stades=c("IND"),
+					datedebut="2015-01-01",
+					datefin="2015-12-31")
+			bM_Arzal<-connect(bM_Arzal)
+			expect_length(bM_Arzal at data,11)
+			rm("envir_stacomi",envir =.GlobalEnv)
+})
+
+test_that("Test example 02_BilanMigration",
+		{
+			# check if built with examples (Rtools install --example)
+			# the file is generate it examples but later loaded to examples from the class using @example
+			# be sure you have built Roxygen documentation before running
+			example_path<-file.path(.libPaths(),"stacomiR","R-ex","BilanMigration-class.R")
+			test<-file.access(example_path,0)
+			if (test!=0) warnings("Package example dir not created ?") else
+				source(example_path)
+		})
+
+
+test_that("Test writing an example to the database",
+		{
+			
+		})
\ No newline at end of file

Modified: pkg/stacomir/man/BilanMigration-class.Rd
===================================================================
--- pkg/stacomir/man/BilanMigration-class.Rd	2016-09-01 18:46:49 UTC (rev 187)
+++ pkg/stacomir/man/BilanMigration-class.Rd	2016-09-01 19:39:15 UTC (rev 188)
@@ -31,6 +31,51 @@
 \note{
 TODO discuss  and how it is used to "write" in the database
 }
+\examples{
+library(stacomiR)
+
+stacomi(gr_interface=FALSE,login_window=FALSE,pre_launch_test=FALSE) 
+## launches the application in the command line
+## here an example of loading
+## not run as the program is possibly not installed
+## this example generates the bM_Arzal dataset
+\dontrun{
+	stacomi(gr_interface=FALSE,
+			login_window=FALSE,
+			pre_launch_test=FALSE)	
+	bM_Arzal=new("BilanMigration")
+	bM_Arzal=choice_c(bM_Arzal,
+			dc=5,
+			taxons=c("Liza ramada"),
+			stades=c("IND"),
+			datedebut="2015-01-01",
+			datefin="2015-12-31")
+	bM_Arzal<-connect(bM_Arzal)
+}
+
+
+data("bM_Arzal")
+# use the following to get the raw data loaded by the connect method
+# not shown there as the database and program might not be installed
+
+#bM_Arzal<-connect(bM_Arzal)
+#str(bM_Arzal at data)
+# calculations
+bM_Arzal<-calcule(bM_Arzal)
+#Individual plot for all DC (standard), taxon and stage where data present
+#silent argument to stop all messages
+plot(bM_Arzal,plot.type="standard",silent=TRUE)
+
+#cumulated migration at the station (all stages and DC grouped)
+plot(bM_Arzal,plot.type="step")
+#some plots are a mixture of french and english
+#changing the reference table names to english should shift all to english.
+#same for spanish.
+# combined plot for ggplot2
+plot(bM_Arzal,plot.type="multiple")
+# data will be written in the data directory specified in the stacomi/calcmig.csv file
+summary(bM_Arzal)
+}
 \author{
 Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
 }

Modified: pkg/stacomir/man/BilanMigrationInterAnnuelle-class.Rd
===================================================================
--- pkg/stacomir/man/BilanMigrationInterAnnuelle-class.Rd	2016-09-01 18:46:49 UTC (rev 187)
+++ pkg/stacomir/man/BilanMigrationInterAnnuelle-class.Rd	2016-09-01 19:39:15 UTC (rev 188)
@@ -19,9 +19,9 @@
 
 \item{\code{stades}}{An object of class \code{\link{RefStades-class}}}
 
-\item{\code{anneedebut}}{Object of class \code{\link{RefAnnee-class}}. refAnnee allows to choose year of beginning}
+\item{\code{anneeDebut}}{Object of class \code{\link{RefAnnee-class}}. refAnnee allows to choose year of beginning}
 
-\item{\code{anneefin}}{Object of class \code{\link{RefAnnee-class}}
+\item{\code{anneeFin}}{Object of class \code{\link{RefAnnee-class}}
 refAnnee allows to choose last year of the Bilan}
 }}
 \section{Objects from the Class}{

Modified: pkg/stacomir/man/calcule-BilanMigration-method.Rd
===================================================================
--- pkg/stacomir/man/calcule-BilanMigration-method.Rd	2016-09-01 18:46:49 UTC (rev 187)
+++ pkg/stacomir/man/calcule-BilanMigration-method.Rd	2016-09-01 19:39:15 UTC (rev 188)
@@ -16,7 +16,7 @@
 \item{silent}{Boolean, if true, information messages are not displays, only warnings and errors}
 }
 \value{
-BilanMigration with slots filled by user choice
+BilanMigration with calcdata slot filled.
 }
 \description{
 does the calculation once data are filled,. It also performs conversion from weight to numbers

Added: pkg/stacomir/man/calcule-BilanMigrationConditionEnv-method.Rd
===================================================================
--- pkg/stacomir/man/calcule-BilanMigrationConditionEnv-method.Rd	                        (rev 0)
+++ pkg/stacomir/man/calcule-BilanMigrationConditionEnv-method.Rd	2016-09-01 19:39:15 UTC (rev 188)
@@ -0,0 +1,21 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/BilanMigrationConditionEnv.r
+\docType{methods}
+\name{calcule,BilanMigrationConditionEnv-method}
+\alias{calcule,BilanMigrationConditionEnv-method}
+\title{Performs the calculations of environment conditions attached to a migration monitoring station}
+\usage{
+\S4method{calcule}{BilanMigrationConditionEnv}(object, ...)
+}
+\arguments{
+\item{object}{An object of class \code{\link{BilanMigrationEnv-class}}}
+
+\item{...}{additional parameters}
+}
+\value{
+\code{\link{BilanMigrationEnv-class}}
+}
+\description{
+Performs the calculations of environment conditions attached to a migration monitoring station
+}
+

Modified: pkg/stacomir/man/fn_EcritBilanJournalier.Rd
===================================================================
--- pkg/stacomir/man/fn_EcritBilanJournalier.Rd	2016-09-01 18:46:49 UTC (rev 187)
+++ pkg/stacomir/man/fn_EcritBilanJournalier.Rd	2016-09-01 19:39:15 UTC (rev 188)
@@ -11,8 +11,8 @@
 \item{bilanMigration}{an object of class \code{\linkS4class{BilanMigration}}}
 }
 \description{
-fn_EcritBilanJournier writes the daily migration in the
-t_bilanmigrationjournalier_bjo table
+Daily values are needed to compare migrations from year to year, by the class \link{BilanMigrationInterAnnuelle-class}. They are added by
+the function fn_EcritBilanJournalier
 }
 \note{
 the user is asked whether or not he wants to overwrite data, if no

Modified: pkg/stacomir/man/fungraph.Rd
===================================================================
--- pkg/stacomir/man/fungraph.Rd	2016-09-01 18:46:49 UTC (rev 187)
+++ pkg/stacomir/man/fungraph.Rd	2016-09-01 19:39:15 UTC (rev 188)
@@ -4,11 +4,15 @@
 \alias{fungraph}
 \title{Function for BilanMigration graphes including numbers DF DC operations}
 \usage{
-fungraph(bilanMigration, tableau, time.sequence, taxon, stade, dc,...)
+fungraph(bilanMigration, tableau, time.sequence, taxon, stade, dc=NULL,silent,...)
 }
 \arguments{
 \item{bilanMigration}{An object of class \code{\linkS4class{BilanMigration}}}
 
+\item{tableau}{A data frame with the with the following columns : No.pas,debut_pas,fin_pas,
+ope_dic_identifiant,lot_tax_code,lot_std_code,type_de_quantite,MESURE,CALCULE,               
+EXPERT,PONCTUEL,Effectif_total,taux_d_echappement,coe_valeur_coefficient}
+
 \item{time.sequence}{A vector POSIXt}
 
 \item{taxon}{The species}
@@ -20,10 +24,6 @@
 \item{silent}{Message displayed or not}
 
 \item{...}{other parameters passed from the plot method to the matplot function}
-
-\item{table=tableau}{A data frame with the with the following columns : No.pas,debut_pas,fin_pas,
-ope_dic_identifiant,lot_tax_code,lot_std_code,type_de_quantite,MESURE,CALCULE,               
-EXPERT,PONCTUEL,Effectif_total,taux_d_echappement,coe_valeur_coefficient}
 }
 \description{
 This graph is for species other than glass eel

Modified: pkg/stacomir/man/plot-BilanMigration-ANY-method.Rd
===================================================================
--- pkg/stacomir/man/plot-BilanMigration-ANY-method.Rd	2016-09-01 18:46:49 UTC (rev 187)
+++ pkg/stacomir/man/plot-BilanMigration-ANY-method.Rd	2016-09-01 19:39:15 UTC (rev 188)
@@ -13,7 +13,7 @@
 
 \item{y}{From the formals but missing}
 
-\item{plot.type}{One of "standard","step","multiple". Defaut to \code{standard} the standard BilanMigration with dc and operation displayed, can also be \code{step} or 
+\item{plot.type}{One of "standard","step". Defaut to \code{standard} the standard BilanMigration with dc and operation displayed, can also be \code{step} or 
 \code{multiple}}
 
 \item{...}{Additional arguments, see \code{plot}, \code{plot.default} and \code{par}}



More information about the Stacomir-commits mailing list