[Stacomir-commits] r209 - in pkg/stacomir: . R inst/tests/testthat man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Sep 15 22:09:28 CEST 2016


Author: briand
Date: 2016-09-15 22:09:28 +0200 (Thu, 15 Sep 2016)
New Revision: 209

Added:
   pkg/stacomir/inst/tests/testthat/test-00zRefclasses.R
Modified:
   pkg/stacomir/DESCRIPTION
   pkg/stacomir/NAMESPACE
   pkg/stacomir/R/BilanEspeces.r
   pkg/stacomir/R/BilanFonctionnementDF.r
   pkg/stacomir/R/BilanMigration.r
   pkg/stacomir/R/BilanMigrationMult.r
   pkg/stacomir/R/Bilan_stades_pigm.r
   pkg/stacomir/R/RefHorodate.r
   pkg/stacomir/R/funstatJournalier.r
   pkg/stacomir/R/interface_BilanConditionEnv.r
   pkg/stacomir/R/interface_BilanFonctionnementDC.r
   pkg/stacomir/R/interface_BilanFonctionnementDF.r
   pkg/stacomir/R/interface_BilanMigration.r
   pkg/stacomir/R/interface_BilanMigrationConditionEnv.r
   pkg/stacomir/R/interface_BilanMigrationInterannuelle.r
   pkg/stacomir/R/interface_BilanMigrationMult.r
   pkg/stacomir/R/interface_BilanMigrationPar.r
   pkg/stacomir/R/interface_Bilan_carlot.r
   pkg/stacomir/R/interface_Bilan_taille.r
   pkg/stacomir/R/interface_bilan_poids_moyen.r
   pkg/stacomir/R/stacomi.r
   pkg/stacomir/R/utilitaires.r
   pkg/stacomir/inst/tests/testthat/test-00stacomir.R
   pkg/stacomir/inst/tests/testthat/test-03BilanFonctionnementDF.R
   pkg/stacomir/man/choice_c-RefHorodate-method.Rd
Log:


Modified: pkg/stacomir/DESCRIPTION
===================================================================
--- pkg/stacomir/DESCRIPTION	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/DESCRIPTION	2016-09-15 20:09:28 UTC (rev 209)
@@ -2,7 +2,7 @@
 Version: 0.5.0
 Date: 2016-09-01
 Title: Fish Migration Monitoring (stacomiR)
-Authors at R: c(person("Cedric", "Briand", role = c("aut", "cre"), email = "cedric.briand at eptb-vilaine.fr"),
+Authors at R: c(person("Cedric", "Briand", role = c("aut", "cre"), email = "cedric.briand00 at gmail.com"),
 	      person("Marion", "Legrand", role = "aut", email="tableau-salt-loire at logrami.fr"))
 Description: Graphical outputs and treatment for a database of fishway
     monitoring. It is a part of the STACOMI project developed in France by the ONEMA

Modified: pkg/stacomir/NAMESPACE
===================================================================
--- pkg/stacomir/NAMESPACE	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/NAMESPACE	2016-09-15 20:09:28 UTC (rev 209)
@@ -60,7 +60,7 @@
 import(sqldf)
 import(stacomirtools)
 import(stringr)
-importFrom(grDevices,X11)
+importFrom(grDevices,dev.new)
 importFrom(grDevices,gray)
 importFrom(grDevices,rainbow)
 importFrom(graphics,axis)

Modified: pkg/stacomir/R/BilanEspeces.r
===================================================================
--- pkg/stacomir/R/BilanEspeces.r	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/R/BilanEspeces.r	2016-09-15 20:09:28 UTC (rev 209)
@@ -292,6 +292,6 @@
 	#gWidgets::addSpring(group)
 	#graphes=ggraphics(width=600,height=400)
 	add(ggrouptotal1,graphes )  # on ajoute au groupe horizontal
-	grDevices::X11()
+	dev.new()
 	assign("graphes",graphes,envir=.GlobalEnv) 
 }
\ No newline at end of file

Modified: pkg/stacomir/R/BilanFonctionnementDF.r
===================================================================
--- pkg/stacomir/R/BilanFonctionnementDF.r	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/R/BilanFonctionnementDF.r	2016-09-15 20:09:28 UTC (rev 209)
@@ -120,22 +120,20 @@
 #' @author Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
 #' @export
 setMethod("choice_c",signature=signature("BilanFonctionnementDF"),definition=function(object,df,horodatedebut,horodatefin,...){
-			# fonctionnementDF<-BfDF
+			# fonctionnementDF<-BfDF;df=2;horodatedebut="2013-01-01";horodatefin="2013-12-31"
 			fonctionnementDF<-object
 			assign("fonctionnementDF",fonctionnementDF,envir=envir_stacomi)    
 			funout(get("msg",envir=envir_stacomi)$interface_BilanFonctionnementDC.1)
 			fonctionnementDF at df<-charge(fonctionnementDF at df)    
 			fonctionnementDF at df<-choice_c(fonctionnementDF at df,df)
-			# assigns the parameter (horodatedebut) of the method to the object using choice_c method for RefDF
-			fonctionnementDF at horodatedebut<-choice_c(fonctionnementDF at horodatedebut,
+			# assigns the parameter (horodatedebut) of the method to the object using choice_c method for RefDC
+			fonctionnementDF at horodatedebut<-choice_c(object=fonctionnementDF at horodatedebut,
 					nomassign="fonctionnementDF_date_debut",
 					funoutlabel=get("msg",envir=envir_stacomi)$interface_Bilan_lot.5,
-					decal=-2,
 					horodate=horodatedebut)
-			fonctionnementDF at horodatefin<-choice_c(fonctionnementDF at horodate,
+			fonctionnementDF at horodatefin<-choice_c(fonctionnementDF at horodatefin,
 					nomassign="fonctionnementDF_date_fin",
 					funoutlabel=get("msg",envir=envir_stacomi)$interface_Bilan_lot.6,
-					decal=-1,
 					horodate=horodatefin)
 			return(fonctionnementDF)
 		})

Modified: pkg/stacomir/R/BilanMigration.r
===================================================================
--- pkg/stacomir/R/BilanMigration.r	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/R/BilanMigration.r	2016-09-15 20:09:28 UTC (rev 209)
@@ -363,7 +363,7 @@
 							#----------------------------------
 							# bilan migration avec poids (civelles
 							#-----------------------------------------
-							#grDevices::X11()
+						
 							fungraph_civelle(bilanMigration=bilanMigration,
 									table=data_without_hole,
 									time.sequence=bilanMigration at time.sequence,
@@ -377,7 +377,6 @@
 							#----------------------------------
 							# bilan migration standard
 							#-----------------------------------------
-							#grDevices::X11()
 							#silent=TRUE
 							fungraph(bilanMigration=bilanMigration,
 									tableau=data_without_hole,

Modified: pkg/stacomir/R/BilanMigrationMult.r
===================================================================
--- pkg/stacomir/R/BilanMigrationMult.r	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/R/BilanMigrationMult.r	2016-09-15 20:09:28 UTC (rev 209)
@@ -373,7 +373,7 @@
 										#----------------------------------
 										# bilan migration avec poids (civelles
 										#-----------------------------------------
-										grDevices::X11()
+										dev.new()
 										fungraph_civelle(bilanMigration=bilanMigrationMult,
 												table=data_without_hole,
 												time.sequence=bilanMigrationMult at time.sequence,
@@ -387,7 +387,7 @@
 										#----------------------------------
 										# bilan migration standard
 										#-----------------------------------------
-										grDevices::X11()
+										dev.new()
 										#silent=TRUE
 										fungraph(bilanMigration=bilanMigrationMult,
 												tableau=data_without_hole,

Modified: pkg/stacomir/R/Bilan_stades_pigm.r
===================================================================
--- pkg/stacomir/R/Bilan_stades_pigm.r	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/R/Bilan_stades_pigm.r	2016-09-15 20:09:28 UTC (rev 209)
@@ -456,10 +456,10 @@
 	VIA3= fnstade(par1=Vparm$pigment_stage[[4]],VB=FALSE,phicum=phicum,neg=FALSE,lmax=lmax)
 	VIA3c=cumsum(VIA3$y)/sum(VIA3$y)  # surface
 	if(graph){
-		grDevices::X11()
+		dev.new()
 		matplot(VB$x,cbind(VB$y,VIA0$y,VIA1$y,VIA2$y,VIA3$y))
 		
-		grDevices::X11()
+		dev.new()
 		matplot(VB$x,cbind(VBc,VIA0c,VIA1c,VIA2c,VIA3c))
 	}
 	#traitement a part de VB
@@ -905,7 +905,7 @@
 	#graphes=ggraphics(width=600,height=400)
 	#add(ggrouptotal1,graphes )  # on ajoute au groupe horizontal       
 	#assign("graphes",graphes,envir=.GlobalEnv) 	
-	grDevices::X11()
+	dev.new()
 	# A cet endroit sinon ouvre plusieurs fenetres pour plusieurs choses
 }
 

Modified: pkg/stacomir/R/RefHorodate.r
===================================================================
--- pkg/stacomir/R/RefHorodate.r	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/R/RefHorodate.r	2016-09-15 20:09:28 UTC (rev 209)
@@ -104,17 +104,18 @@
 #' @param label Label for the gframe
 #' @param nomassing The name assigned in environment envir_stacomi
 #' @param funoutlabel, text displayed by the interface
-#' @param decale Default 0, number of years to shift forward or backward, the date will be set to the first day of the year
 #' @param affichecal Default TRUE, should the calendar be displayed
-#' @param horodate The horodate to set, formats "%d/%m/%Y %H:%M:%s", "%d/%m/%y %H:%M:%s", "%Y-%m-%d  %H:%M:%s"
+#' @param horodate The horodate to set, formats "\%d/\%m/\%Y \%H:\%M:\%s", "\%d/\%m/\%y \%H:\%M:\%s", "\%Y-\%m-\%d  \%H:\%M:\%s" formats
+#' can also be passed with the date set to the minute \%d/\%m/\%Y \%H:\%M or the day  \%d/\%m/\%Y
 #' \dots are accepted
 #' @return An object of class \link{RefHorodate-class} with slot \emph{horodate} set
 setMethod("choice_c",signature=signature("RefHorodate"),definition=function(object,
 				nomassign="horodate",
 				funoutlabel="nous avons le choix dans la date\n",
-				decal=0,
+				#decal=0,
 				horodate
 		) {
+			# horodate="2013-01-01"
 			# parse the horohorodate
 			if (length(horodate)>1) stop("horodate should be a vector of length 1")
 			if (is.null(horodate)) stop("horodate should not be null")
@@ -130,6 +131,12 @@
 					if (is.na(.horodate)){
 						.horodate=strptime(horodate, format="%d/%m/%Y %H:%M")				
 					}
+					if (is.na(.horodate)){
+						.horodate=strptime(horodate, format="%d/%m/%y")				
+					}
+					if (is.na(.horodate)){
+						.horodate=strptime(horodate, format="%d/%m/%Y")				
+					}
 				} else if (grepl("-",horodate)){
 					.horodate=strptime(horodate, format="%Y-%m-%d  %H:%M:%s")
 					if (is.na(.horodate)){
@@ -141,6 +148,12 @@
 					if (is.na(.horodate)){
 						.horodate=strptime(horodate, format="%d-%m-%Y  %H:%M")				
 					}
+					if (is.na(.horodate)){
+						.horodate=strptime(horodate, format="%Y-%m-%d")				
+					}
+					if (is.na(.horodate)){
+						.horodate=strptime(horodate, format="%d-%m-%Y")				
+					}
 				}
 		
 			} else if (class(horodate)=="Date"){
@@ -148,20 +161,12 @@
 			} else if (class(horodate)[2]=="POSIXt"){
 				.horodate=horodate
 			}
+			if (is.na(.horodate)) stop("Formatting problem, the character vector you are trying to pass as horodate could not
+be parsed. Check example or documentation")
 			object at horodate=.horodate	
-			if (decal!=0){
-				# Returns the first horodate of a year shifted by decal
-				# @param horodate The horodate to shift (class POSIXt)
-				# @param decal number of year to shift
-				# @return A POSIXt
-				shiftyear<-function(horodate,decal){
-					anneeprec=as.numeric(strftime(horodate,"%Y"))+decal
-					return(strptime(paste(anneeprec,"-01-01",sep=""),format="%Y-%m-%d"))
-				}
-				object at horodate<-shiftyear(object at horodate,decal)
-			}
 			validObject(object)				
 			assign(nomassign,object,envir_stacomi)
 			funout(funoutlabel)	
+			return(object)
 		})
 

Modified: pkg/stacomir/R/funstatJournalier.r
===================================================================
--- pkg/stacomir/R/funstatJournalier.r	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/R/funstatJournalier.r	2016-09-15 20:09:28 UTC (rev 209)
@@ -11,7 +11,7 @@
 	annee=unique(strftime(as.POSIXlt(time.sequence),"%Y"))
 	somme=tapply(tableau$Effectif_total, mois, sum, na.rm=TRUE) # sums
 	moyennes_journalieres=tapply(tableau$Effectif_total, mois, mean, na.rm=TRUE) # means
-	ecarts_types=tapply(tableau$Effectif_total, mois, sd, na.rm=TRUE) # std. deviations
+	ecarts_types=tapply(tableau$Effectif_total, mois, stats::sd, na.rm=TRUE) # std. deviations
 	nombre=as.integer(tapply(tableau$Effectif_total, mois, function(x) sum(!is.na(x)))) # counts
 	resum=rbind(nombre,somme,moyennes_journalieres,ecarts_types)
 	
@@ -27,7 +27,7 @@
 	resum=data.frame(resum)
 	resum["somme","bilan"]=round(sum(tableau$Effectif_total, na.rm=TRUE),2)
 	resum["moyennes_journalieres","bilan"]=round(mean(tableau$Effectif_total, na.rm=TRUE),2)
-	resum["ecarts_types","bilan"]=round(sd(tableau$Effectif_total, na.rm=TRUE),2)
+	resum["ecarts_types","bilan"]=round(stats::sd(tableau$Effectif_total, na.rm=TRUE),2)
 	if (taxon=="Anguilla anguilla"& stade=="civelle") 
 	{
 		resum["poids_depuis_effectif","bilan"]=round(sum(tableau$poids_depuis_effectif, na.rm=TRUE),2)

Modified: pkg/stacomir/R/interface_BilanConditionEnv.r
===================================================================
--- pkg/stacomir/R/interface_BilanConditionEnv.r	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/R/interface_BilanConditionEnv.r	2016-09-15 20:09:28 UTC (rev 209)
@@ -42,5 +42,5 @@
     #graphes=ggraphics(width=600,height=400)
     #add(ggrouptotal1,graphes )  # on ajoute au groupe horizontal
     #assign("graphes",graphes,envir=envir_stacomi)
-	grDevices::X11()
+	dev.new()
 }
\ No newline at end of file

Modified: pkg/stacomir/R/interface_BilanFonctionnementDC.r
===================================================================
--- pkg/stacomir/R/interface_BilanFonctionnementDC.r	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/R/interface_BilanFonctionnementDC.r	2016-09-15 20:09:28 UTC (rev 209)
@@ -49,5 +49,5 @@
     #add(ggrouptotal1,graphes )  # on ajoute au groupe horizontal
     # A cet endroit sinon ouvre plusieurs fenetres pour plusieurs choses
     #assign("graphes",graphes,envir=envir_stacomi)
-	grDevices::X11()
+	dev.new()
 }
\ No newline at end of file

Modified: pkg/stacomir/R/interface_BilanFonctionnementDF.r
===================================================================
--- pkg/stacomir/R/interface_BilanFonctionnementDF.r	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/R/interface_BilanFonctionnementDF.r	2016-09-15 20:09:28 UTC (rev 209)
@@ -13,16 +13,17 @@
    gWidgets::add(ggroupboutons,group)
     
     choice(fonctionnementDF at df)
+	# here decale =-1 or -2 will make the bilan for the year preceeding the current date
 	choice(fonctionnementDF at horodatedebut,
 			label=get("msg",envir=envir_stacomi)$interface_Bilan_lot.3,
 			nomassign="fonctionnementDF_date_debut",
 			funoutlabel=get("msg",envir=envir_stacomi)$interface_Bilan_lot.5,
-			decal=-2)
+			decal=-1)
 	choice(fonctionnementDF at horodatefin,
 			label=get("msg",envir=envir_stacomi)$interface_Bilan_lot.4,
 			nomassign="fonctionnementDF_date_fin",
 			funoutlabel=get("msg",envir=envir_stacomi)$interface_Bilan_lot.6,
-			decal=-1)
+			decal=-2)
 	
     aBarchart=gWidgets::gaction(label="barchart",icon="barplot",handler=funbarchartDF,tooltip=get("msg",envir=envir_stacomi)$interface_BilanFonctionnementDC.2)          
     aBox=gWidgets::gaction(label="boites",icon="graph2",handler=funboxDF,tooltip=get("msg",envir=envir_stacomi)$interface_BilanFonctionnementDC.3)
@@ -38,5 +39,5 @@
     add(group, gmenu(toolbarlist))
     add(group,gbutton(text = "graph", handler = function(h,...){X11()})) 
     gWidgets::addSpring(group)
-	grDevices::X11()
+	dev.new()
 }
\ No newline at end of file

Modified: pkg/stacomir/R/interface_BilanMigration.r
===================================================================
--- pkg/stacomir/R/interface_BilanMigration.r	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/R/interface_BilanMigration.r	2016-09-15 20:09:28 UTC (rev 209)
@@ -34,5 +34,5 @@
 	#graphes=ggraphics(width=600,height=600)
 	#add(ggrouptotal1,graphes )  # on ajoute au groupe horizontal
 	#assign("graphes",graphes,envir=envir_stacomi) 
-	grDevices::X11()
+	dev.new()
 }
\ No newline at end of file

Modified: pkg/stacomir/R/interface_BilanMigrationConditionEnv.r
===================================================================
--- pkg/stacomir/R/interface_BilanMigrationConditionEnv.r	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/R/interface_BilanMigrationConditionEnv.r	2016-09-15 20:09:28 UTC (rev 209)
@@ -36,5 +36,5 @@
 	#graphes=ggraphics(width=600,height=400)
 	#add(ggrouptotal1,graphes )  # on ajoute au groupe horizontal
 	#assign("graphes",graphes,envir=envir_stacomi)
-	grDevices::X11()
+	dev.new()
 }
\ No newline at end of file

Modified: pkg/stacomir/R/interface_BilanMigrationInterannuelle.r
===================================================================
--- pkg/stacomir/R/interface_BilanMigrationInterannuelle.r	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/R/interface_BilanMigrationInterannuelle.r	2016-09-15 20:09:28 UTC (rev 209)
@@ -89,7 +89,7 @@
 	#graphes=ggraphics(width=600,height=400)
 	#add(ggrouptotal1,graphes )  # on ajoute au groupe horizontal
 	#assign("graphes",graphes,envir=envir_stacomi) 
-	grDevices::X11()
+	dev.new()
 	
 # A cet endroit sinon ouvre plusieurs fenetres pour plusieurs choses
 	

Modified: pkg/stacomir/R/interface_BilanMigrationMult.r
===================================================================
--- pkg/stacomir/R/interface_BilanMigrationMult.r	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/R/interface_BilanMigrationMult.r	2016-09-15 20:09:28 UTC (rev 209)
@@ -46,6 +46,6 @@
 	#graphes=ggraphics(width=650,height=650)
 	#add(ggrouptotal1,graphes )  # on ajoute au groupe horizontal
 	#assign("graphes",graphes,envir=envir_stacomi) 
-	grDevices::X11()
+	dev.new()
 }
 

Modified: pkg/stacomir/R/interface_BilanMigrationPar.r
===================================================================
--- pkg/stacomir/R/interface_BilanMigrationPar.r	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/R/interface_BilanMigrationPar.r	2016-09-15 20:09:28 UTC (rev 209)
@@ -45,6 +45,6 @@
     #graphes=ggraphics(width=600,height=400)
     #add(ggrouptotal1,graphes )  # on ajoute au groupe horizontal
     #assign("graphes",graphes,envir=envir_stacomi)
-	grDevices::X11()
+	dev.new()
 
 }
\ No newline at end of file

Modified: pkg/stacomir/R/interface_Bilan_carlot.r
===================================================================
--- pkg/stacomir/R/interface_Bilan_carlot.r	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/R/interface_Bilan_carlot.r	2016-09-15 20:09:28 UTC (rev 209)
@@ -78,6 +78,6 @@
     #graphes=ggraphics(width=600,height=400)
     #add(ggrouptotal1,graphes )  # on ajoute au groupe horizontal       
     #assign("graphes",graphes,envir=envir_stacomi) 
-	grDevices::X11()
+	dev.new()
     # A cet endroit sinon ouvre plusieurs fenetres pour plusieurs choses
 }

Modified: pkg/stacomir/R/interface_Bilan_taille.r
===================================================================
--- pkg/stacomir/R/interface_Bilan_taille.r	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/R/interface_Bilan_taille.r	2016-09-15 20:09:28 UTC (rev 209)
@@ -54,7 +54,7 @@
 	#graphes=ggraphics(width=600,height=400)
 	#add(ggrouptotal1,graphes )  # on ajoute au groupe horizontal
 	#assign("graphes",graphes,envir=envir_stacomi)
-	grDevices::X11()	
+	dev.new()	
 	assign("toolbarlist",toolbarlist,envir=.GlobalEnv)
 	assign("ggroupboutonsbas",ggroupboutonsbas,envir =.GlobalEnv)
 }

Modified: pkg/stacomir/R/interface_bilan_poids_moyen.r
===================================================================
--- pkg/stacomir/R/interface_bilan_poids_moyen.r	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/R/interface_bilan_poids_moyen.r	2016-09-15 20:09:28 UTC (rev 209)
@@ -28,7 +28,7 @@
     #graphes=ggraphics(width=600,height=400)
     #add(ggrouptotal1,graphes )  # on ajoute au groupe horizontal
     #assign("graphes",graphes,envir=envir_stacomi)
-	grDevices::X11()
+	dev.new()
     # A cet endroit sinon ouvre plusieurs fenetres pour plusieurs choses
     choice(bilan_poids_moyen at liste)
     choice(bilan_poids_moyen at dc,objectBilan=NULL,is.enabled=TRUE)

Modified: pkg/stacomir/R/stacomi.r
===================================================================
--- pkg/stacomir/R/stacomi.r	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/R/stacomi.r	2016-09-15 20:09:28 UTC (rev 209)
@@ -223,7 +223,7 @@
 	eval(interface_chooselang(),envir = .GlobalEnv)
 }
 hX11=function(h,...){
-	grDevices::X11()
+	dev.new()
 }
 
 
@@ -283,13 +283,15 @@
 #' @importFrom utils select.list write.table data
 #' @importFrom stats ftable
 #' @importFrom stats xtabs
+#' @importFrom grDevices dev.new
+#' @importFrom stats sd
 #' @importFrom reshape2 dcast
 #' @importFrom reshape2 melt
 #' @importFrom lattice barchart trellis.par.get trellis.par.set simpleKey
 #' @importFrom grid gpar
 #' @importFrom graphics layout matplot mtext points polygon segments par axis text legend rect axis.Date
 #' @importFrom stats as.formula coef na.fail nls pbeta predict sd
-#' @importFrom grDevices X11 X11 gray rainbow
+#' @importFrom grDevices gray rainbow
 #' @author Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
 #' @examples
 #' 

Modified: pkg/stacomir/R/utilitaires.r
===================================================================
--- pkg/stacomir/R/utilitaires.r	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/R/utilitaires.r	2016-09-15 20:09:28 UTC (rev 209)
@@ -138,11 +138,11 @@
 			# the access to csv file failed despite database_expected=true
 			# if the file does not open, we switch to the file located within the package
 			cat("C:/program files/calcmig.csv does not exist, switching to defaut package file")
-			data("calcmig")				
+			data("calcmig",envir=environment())				
 		}
 	} else {
 		# no access to the database is expected, we are using the file in the data directory of the package
-		data("calcmig")
+		data("calcmig",envir=environment())
 		test<-FALSE
 	}
 	tableau_config = t(calcmig) # renvoit une liste

Modified: pkg/stacomir/inst/tests/testthat/test-00stacomir.R
===================================================================
--- pkg/stacomir/inst/tests/testthat/test-00stacomir.R	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/inst/tests/testthat/test-00stacomir.R	2016-09-15 20:09:28 UTC (rev 209)
@@ -1,9 +1,9 @@
 context("stacomi base connection")
 
 test_that("Test existence of csv file",{
-		filecsv<-"C:/Program Files/stacomi/calcmig.csv";
-		expect_equivalent(file.access(filecsv,0),0)
-	}
+			filecsv<-"C:/Program Files/stacomi/calcmig.csv";
+			expect_equivalent(file.access(filecsv,0),0)
+		}
 
 )
 
@@ -11,7 +11,7 @@
 			data("calcmig",package = "stacomiR")
 			calcmig<-calcmig
 			expect_equal(length(calcmig),11)
-
+			
 		}
 
 )
@@ -28,19 +28,19 @@
 context("Database connection")
 
 test_that("Test that stacomirtools connects",{
-	require(stacomiR)
-	envir_stacomi <<- new.env(parent = emptyenv())
-	msg<-messages()
-	mylinks=chargecsv(database_expected=TRUE)
-	baseODBC=mylinks[["baseODBC"]]	
-	con=new("ConnectionODBC")	
-	con at baseODBC=baseODBC
-	con<-connect(con)
-	expect_is(connect(con),'ConnectionODBC')
-	expect_equal(con at etat,NULL)
-	odbcCloseAll()
-	rm("envir_stacomi",envir =.GlobalEnv)
-})
+			require(stacomiR)
+			envir_stacomi <<- new.env(parent = emptyenv())
+			msg<-messages()
+			mylinks=chargecsv(database_expected=TRUE)
+			baseODBC=mylinks[["baseODBC"]]	
+			con=new("ConnectionODBC")	
+			con at baseODBC=baseODBC
+			con<-connect(con)
+			expect_is(connect(con),'ConnectionODBC')
+			expect_equal(con at etat,NULL)
+			odbcCloseAll()
+			rm("envir_stacomi",envir =.GlobalEnv)
+		})
 
 test_that("Test that positive count for nrow(ref.tr_taxon_tax)",{
 			require(stacomiR)
@@ -90,7 +90,7 @@
 			expect_true(exists("logw"))
 			dispose(logw)
 			rm("envir_stacomi",envir =.GlobalEnv)
-})
+		})
 
 test_that("Test that gWidget gr_interface is loaded, without database_expected, nor login window",{
 			require(stacomiR)
@@ -137,5 +137,142 @@
 			# objects should have the same length but different languages
 			expect_identical(length(msg),length(msgbase))
 			rm("envir_stacomi",envir =.GlobalEnv)
-			rm(list=ls(all=TRUE))
 		})
+
+
+context("Database integrity")
+
+
+test_that("Test that tickets have been launched",
+		{
+			require(stacomiR)
+			stacomi(gr_interface=FALSE,login_window=FALSE,database_expected=FALSE)
+			req<-new("RequeteODBC")
+			req at baseODBC<-get("baseODBC", envir=envir_stacomi)		
+			sch=get("sch",envir=envir_stacomi)
+			req at sql=paste("select * from ",sch," ts_maintenance_main")
+			req<-stacomirtools::connect(req)
+			result<-req at query
+			# using dput(ticket)
+			tickets<-structure(list(
+							main_ticket = c(59L,
+									40L,
+									42L, 
+									67L,
+									72L, 
+									121L, 
+									122L, 
+									81L, 
+									61L, 
+									152L, 
+									147L), main_description = c("creation de la table de maintenance", 
+									"ajout des clé étrangères manquantes", 
+									"modification des propriétaires sur les tables à séquence et grant select sur ref.tr_typedf_tdf oublié", 
+									"org code rajouté dans les tables t_operationmarquage_omq, tj_coefficientconversion_coe,tj_prelevementlot_prl", 
+									"creation d'une tableref.ts_messager_msr  pour l'internationalisation", 
+									"ajout de la notion de cohorte pour les saumons passant très précocément", 
+									"Mise à jour des localisations anatomiques", 
+									"Mise à jour vers la version 0.4 alpha, mise à jour des référentiels du SANDRE, script ticjet81_mise_en_conformite_sandre, révision 98", 
+									"Mise à jour vers la version 0.4 alpha, mise à jour ds constraintes stationmesure modification limites coordonnées géographiques", 
+									"Mise à jour vers la version 0.4 alpha, problèmes de clé étrangères, script total", 
+									"Mise à jour vers la version 0.4 alpha, creation des masques"
+							)), 
+					.Names = c("main_ticket", "main_description"), 
+					class = "data.frame",
+					row.names = c(NA, 
+							11L))
+			check_exist_tickets=tickets$main_ticket%in%result$main_ticket
+			for (i in 1:nrow(tickets)){
+				expect_true(check_exist_tickets[i],label=paste('Missing ticket :',tickets$main_ticket[i]))
+			}					
+		})
+
+test_that("All foreign keys are present",
+		{
+			require(stacomiR)
+			stacomi(gr_interface=FALSE,login_window=FALSE,database_expected=FALSE)
+			req<-new("RequeteODBC")
+			baseODBC<-get("baseODBC", envir=envir_stacomi)	
+			baseODBC$uid=readline(prompt="Enter superuser name: ")
+			baseODBC$pwd=readline(prompt="Enter superuser password: ")	
+			req at baseODBC<-baseODBC
+			req at sql=paste("SELECT
+							distinct on (tc.constraint_name) tc.constraint_name, tc.table_name
+							FROM 
+							information_schema.table_constraints AS tc 
+							JOIN information_schema.key_column_usage AS kcu
+							ON tc.constraint_name = kcu.constraint_name
+							JOIN information_schema.constraint_column_usage AS ccu
+							ON ccu.constraint_name = tc.constraint_name
+							WHERE constraint_type = 'FOREIGN KEY';")
+			req<-stacomirtools::connect(req)
+			result<-req at query
+			fk<-structure(list(constraint_name = c("c_fk_act_lot_identifiant", 
+									"c_fk_act_mqe_reference", "c_fk_act_org_code", "c_fk_bjo_org_code", 
+									"c_fk_bjo_std_code", "c_fk_bjo_tax_code", "c_fk_bme_std_code", 
+									"c_fk_bme_tax_code", "c_fk_car_lot_identifiant", "c_fk_car_org_code", 
+									"c_fk_car_par_code", "c_fk_car_val_identifiant", "c_fk_coe_org_code", 
+									"c_fk_coe_qte_code", "c_fk_coe_std_code", "c_fk_coe_tax_code", 
+									"c_fk_dft_df_identifiant", "c_fk_dft_org_code", "c_fk_dft_tdf_code", 
+									"c_fk_dic_dif_identifiant", "c_fk_dic_dis_identifiant", "c_fk_dic_org_code", 
+									"c_fk_dic_tdc_code", "c_fk_dif_dis_identifiant", "c_fk_dif_org_code", 
+									"c_fk_dif_ouv_identifiant", "c_fk_dtx_dif_identifiant", "c_fk_dtx_org_code", 
+									"c_fk_dtx_tax_code", "c_fk_env_org_code", "c_fk_env_stm_identifiant", 
+									"c_fk_env_val_identifiant", "c_fk_lot_dev_code", "c_fk_lot_lot_identifiant", 
+									"c_fk_lot_ope_identifiant", "c_fk_lot_org_code", "c_fk_lot_qte_code", 
+									"c_fk_lot_std_code", "c_fk_lot_tax_code", "c_fk_maa_mal_id", 
+									"c_fk_mac_valeurqualitatifdefaut", "c_fk_mae_mao_id", "c_fk_mae_stm_identifiant", 
+									"c_fk_mal_mas_id", "c_fk_mao_mas_id", "c_fk_mqe_loc_code", "c_fk_mqe_nmq_code", 
+									"c_fk_mqe_omq_reference", "c_fk_mqe_org_code", "c_fk_mrl_msr_id", 
+									"c_fk_omq_org_code", "c_fk_ope_dic_identifiant", "c_fk_ope_org_code", 
+									"c_fk_ouv_nov_code", "c_fk_ouv_org_code", "c_fk_ouv_sta_code", 
+									"c_fk_pco_imp_code", "c_fk_pco_loc_code", "c_fk_pco_lot_identifiant", 
+									"c_fk_pco_org_code", "c_fk_pco_pat_code", "c_fk_per_dis_identifiant", 
+									"c_fk_per_org_code", "c_fk_per_tar_code", "c_fk_prl_loc_code", 
+									"c_fk_prl_lot_identifiant", "c_fk_prl_org_code", "c_fk_prl_pre_nom", 
+									"c_fk_prl_typeprelevement", "c_fk_qal_par_code", "c_fk_qan_par_code", 
+									"c_fk_sta_org_code", "c_fk_std_code", "c_fk_stm_org_code", "c_fk_stm_par_code", 
+									"c_fk_stm_sta_code", "c_fk_tav_dic_identifiant", "c_fk_tav_org_code", 
+									"c_fk_tax_ntx_code", "c_fk_tax_tax_tax_code", "c_fk_txe_ech_code", 
+									"c_fk_txe_org_code", "c_fk_txe_ouv_identifiant", "c_fk_txe_sta_code", 
+									"c_fk_txe_std_code", "c_fk_txe_tax_code", "c_fk_txv_org_code", 
+									"c_fk_txv_std_code", "c_fk_txv_tax_code", "c_fk_val_qal_code"
+							), table_name = c("tj_actionmarquage_act", "tj_actionmarquage_act", 
+									"tj_actionmarquage_act", "t_bilanmigrationjournalier_bjo", "t_bilanmigrationjournalier_bjo", 
+									"t_bilanmigrationjournalier_bjo", "t_bilanmigrationmensuel_bme", 
+									"t_bilanmigrationmensuel_bme", "tj_caracteristiquelot_car", "tj_caracteristiquelot_car", 
+									"tj_caracteristiquelot_car", "tj_caracteristiquelot_car", "tj_coefficientconversion_coe", 
+									"tj_coefficientconversion_coe", "tj_coefficientconversion_coe", 
+									"tj_coefficientconversion_coe", "tj_dfesttype_dft", "tj_dfesttype_dft", 
+									"tj_dfesttype_dft", "t_dispositifcomptage_dic", "t_dispositifcomptage_dic", 
+									"t_dispositifcomptage_dic", "t_dispositifcomptage_dic", "t_dispositiffranchissement_dif", 
+									"t_dispositiffranchissement_dif", "t_dispositiffranchissement_dif", 
+									"tj_dfestdestinea_dtx", "tj_dfestdestinea_dtx", "tj_dfestdestinea_dtx", 
+									"tj_conditionenvironnementale_env", "tj_conditionenvironnementale_env", 
+									"tj_conditionenvironnementale_env", "t_lot_lot", "t_lot_lot", 
+									"t_lot_lot", "t_lot_lot", "t_lot_lot", "t_lot_lot", "t_lot_lot", 
+									"ts_masqueordreaffichage_maa", "ts_masquecaracteristiquelot_mac", 
+									"ts_masqueconditionsenvironnementales_mae", "ts_masqueconditionsenvironnementales_mae", 
+									"ts_masquelot_mal", "ts_masqueope_mao", "t_marque_mqe", "t_marque_mqe", 
+									"t_marque_mqe", "t_marque_mqe", "ts_messagerlang_mrl", "t_operationmarquage_omq", 
+									"t_operation_ope", "t_operation_ope", "t_ouvrage_ouv", "t_ouvrage_ouv", 
+									"t_ouvrage_ouv", "tj_pathologieconstatee_pco", "tj_pathologieconstatee_pco", 
+									"tj_pathologieconstatee_pco", "tj_pathologieconstatee_pco", "tj_pathologieconstatee_pco", 
+									"t_periodefonctdispositif_per", "t_periodefonctdispositif_per", 
+									"t_periodefonctdispositif_per", "tj_prelevementlot_prl", "tj_prelevementlot_prl", 
+									"tj_prelevementlot_prl", "tj_prelevementlot_prl", "tj_prelevementlot_prl", 
+									"tr_parametrequalitatif_qal", "tr_parametrequantitatif_qan", 
+									"t_station_sta", "ts_taxonvideo_txv", "tj_stationmesure_stm", 
+									"tj_stationmesure_stm", "tj_stationmesure_stm", "ts_taillevideo_tav", 
+									"ts_taillevideo_tav", "tr_taxon_tax", "tr_taxon_tax", "tj_tauxechappement_txe", 
+									"tj_tauxechappement_txe", "tj_tauxechappement_txe", "tj_tauxechappement_txe", 
+									"tj_tauxechappement_txe", "tj_tauxechappement_txe", "ts_taxonvideo_txv", 
+									"ts_taxonvideo_txv", "ts_taxonvideo_txv", "tr_valeurparametrequalitatif_val"
+							)), .Names = c("constraint_name", "table_name"), row.names = c(NA, 
+							90L), class = "data.frame")
+					check_exist_fk=fk$constraint_name%in%result$constraint_name
+					for (i in 1:nrow(fk)){
+						expect_true(check_exist_fk[i],label=paste("Missing foreign key :",fk$constraint_name,"table :",fk$table_name))
+					}
+					rm(list=ls(all=TRUE))	
+		})
\ No newline at end of file

Added: pkg/stacomir/inst/tests/testthat/test-00zRefclasses.R
===================================================================
--- pkg/stacomir/inst/tests/testthat/test-00zRefclasses.R	                        (rev 0)
+++ pkg/stacomir/inst/tests/testthat/test-00zRefclasses.R	2016-09-15 20:09:28 UTC (rev 209)
@@ -0,0 +1,48 @@
+context("RefHorodate")
+test_that("Test that the parsing of many kind of dates works",
+		{
+			require(stacomiR)
+			refHorodate<-new("RefHorodate")
+			# regular expression to test string "1] nous avons le choix dans la date\n"
+			# default string returned by the method
+			expect_that(refHorodate<-choice_c(refHorodate,	
+							horodate="01/01/2013 00:00:00"),prints_text("^\\[1\\].+date.+"))
+			expect_that(refHorodate<-choice_c(refHorodate,	
+							horodate="01/01/2013 00:00"),prints_text("^\\[1\\].+date.+"))
+			expect_that(refHorodate<-choice_c(refHorodate,	
+							horodate="01-01-2013 00:00"),prints_text("^\\[1\\].+date.+"))		
+			expect_that(refHorodate<-choice_c(refHorodate,	
+							horodate="2013-01-01 00:00"),prints_text("^\\[1\\].+date.+"))	
+			expect_that(refHorodate<-choice_c(refHorodate,	
+							horodate="01-01-2013"),prints_text("^\\[1\\].+date.+"))				
+			refHorodate<-choice_c(refHorodate,	
+					horodate="2013/01/01 00:00:00")	
+			rm("envir_stacomi",envir =.GlobalEnv)
+		})
+
+
+
+test_that("Test that the parsing of wrong character formats gets an error",
+		{
+			require(stacomiR)
+			refHorodate<-new("RefHorodate")
+			expect_error(refHorodate<-choice_c(refHorodate,	
+							horodate="2013 01 01"))				
+			rm("envir_stacomi",envir =.GlobalEnv)
+		})
+
+context("RefDF")
+
+test_that("Test that RefDF choice_c method loads character, numeric, but not rubbish",
+		{
+			require(stacomiR)
+			stacomi(gr_interface=FALSE,login_window=FALSE,database_expected=FALSE)
+			refDF<-new("RefDF")
+			refDF<-charge(refDF)
+			expect_silent(refDF<-choice_c(refDF,	2))		
+			expect_silent(refDF<-choice_c(refDF,	"2"))	
+			options(warn = 0)
+			expect_error(refDF<-choice_c(refDF,	"semoule"))
+			options(warn = 2)
+			rm("envir_stacomi",envir =.GlobalEnv)
+		})

Modified: pkg/stacomir/inst/tests/testthat/test-03BilanFonctionnementDF.R
===================================================================
--- pkg/stacomir/inst/tests/testthat/test-03BilanFonctionnementDF.R	2016-09-11 19:23:57 UTC (rev 208)
+++ pkg/stacomir/inst/tests/testthat/test-03BilanFonctionnementDF.R	2016-09-15 20:09:28 UTC (rev 209)
@@ -11,18 +11,20 @@
 			assign("sch","iav.",envir_stacomi)
 			
 			BfDF<-new("BilanFonctionnementDF")
-			options(warn = 2)
 			BfDF<-choice_c(BfDF,
 					2,
 					horodatedebut="2013-01-01",
 					horodatefin="2013-12-31")
-			options(warn = 0)
-			# there should be data in 
 			expect_gt(nrow(BfDF at df@data),0,
 					label="There should be data loaded by the choice_c method in the data slot of 
 the RefDF slot,nrow(BfDF at df@data)")				
 			expect_s4_class(BfDF,
 					"BilanMigration")
-			rm("envir_stacomi",envir =.GlobalEnv)
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/stacomir -r 209


More information about the Stacomir-commits mailing list