[Stacomir-commits] r410 - in pkg: stacomir/R stacomirtools stacomirtools/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jun 21 17:19:14 CEST 2017


Author: briand
Date: 2017-06-21 17:19:14 +0200 (Wed, 21 Jun 2017)
New Revision: 410

Modified:
   pkg/stacomir/R/report_annual.R
   pkg/stacomir/R/report_mig_mult.R
   pkg/stacomirtools/DESCRIPTION
   pkg/stacomirtools/R/ConnectionODBC.r
   pkg/stacomirtools/R/RequeteODBC.r
Log:
solving error with sqldf and Rsqlite2.0

the problem has been removed and my computer passes R checks

Modified: pkg/stacomir/R/report_annual.R
===================================================================
--- pkg/stacomir/R/report_annual.R	2017-06-21 06:21:15 UTC (rev 409)
+++ pkg/stacomir/R/report_annual.R	2017-06-21 15:19:14 UTC (rev 410)
@@ -147,14 +147,15 @@
 			as.numeric(end_of_the_year)/as.numeric(operation_duration)
 		data_end_of_the_year$ope_date_fin<-round_years
 		final_data<-rbind(data_not_to_cut,data_beginning_of_the_year,data_end_of_the_year)
-		r_ann at data<-sqldf(" select sum(lot_effectif) as effectif, annee_debut as annee, 
+		r_ann at data<-sqldf(x=" select sum(lot_effectif) as effectif, annee_debut as annee, 
 				ope_dic_identifiant,
 				lot_tax_code, 
 				lot_std_code  
 				from 
 				final_data							
 				group by annee, ope_dic_identifiant, lot_tax_code, lot_std_code 
-				order by ope_dic_identifiant, annee, lot_tax_code, lot_std_code; ")
+				order by ope_dic_identifiant, annee, lot_tax_code, lot_std_code; ",
+                    drv="PostgreSQL")
 		
 	  }
 	  #If we have dc and years with no difference in the years of start and end for the same operation we calculate the "classical" sum by year

Modified: pkg/stacomir/R/report_mig_mult.R
===================================================================
--- pkg/stacomir/R/report_mig_mult.R	2017-06-21 06:21:15 UTC (rev 409)
+++ pkg/stacomir/R/report_mig_mult.R	2017-06-21 15:19:14 UTC (rev 410)
@@ -513,12 +513,13 @@
 		  grdata<-rbind(grdata,data)
 		}
 		names(grdata)<-tolower(names(grdata))
-		grdata<-sqldf::sqldf("select sum(effectif_total) as effectif_total,
+		grdata<-sqldf::sqldf(x="select sum(effectif_total) as effectif_total,
 				\"no.pas\",
 				debut_pas
 				from grdata
 				group by debut_pas,\"no.pas\"
-				order by debut_pas")
+				order by debut_pas",
+                    drv="PostgreSQL")
 		grdata_without_hole<-merge(
 			data.frame(no.pas=as.numeric(strftime(report_mig_mult at time.sequence,format="%j"))-1,
 				debut_pas=report_mig_mult at time.sequence),
@@ -893,10 +894,10 @@
 	  ts_id=as.numeric(strftime(time.sequence,format="%j")),stringsAsFactors =FALSE)
   dfts<-merge(df.ts,df,by="ts_id")
   datasub1<-merge(dfts,datasub,by="lot_identifiant")
-# ci dessous pour faire du group by c'est quand meme bien de passer par sqldf
+# to do a group by it is good to use sqldf
   datasub1$value<-as.numeric(datasub1$value) # sinon arrondis e des entiers
   if (negative){
-	datasub2<-sqldf::sqldf("SELECT  debut_pas,
+	datasub2<-sqldf::sqldf(x="SELECT  debut_pas,
 			fin_pas,
 			sum(value*coef) as value,
 			type_de_quantite,
@@ -920,10 +921,11 @@
 			FROM datasub1 		
 			where value>=0
 			GROUP BY ope_dic_identifiant,lot_tax_code, lot_std_code, lot_methode_obtention, debut_pas,fin_pas,type_de_quantite
-			ORDER BY ope_dic_identifiant,debut_pas, lot_tax_code, lot_std_code,type_de_quantite"
+			ORDER BY ope_dic_identifiant,debut_pas, lot_tax_code, lot_std_code,type_de_quantite",
+        drv="PostgreSQL"
 	)
   } else {
-	datasub2<-sqldf::sqldf("SELECT  debut_pas,
+	datasub2<-sqldf::sqldf(x="SELECT  debut_pas,
 			fin_pas,
 			sum(value*coef) as value,
 			type_de_quantite,
@@ -933,7 +935,8 @@
 			lot_methode_obtention 	
 			FROM datasub1 		
 			GROUP BY ope_dic_identifiant,lot_tax_code, lot_std_code, lot_methode_obtention, debut_pas,fin_pas,type_de_quantite
-			ORDER BY ope_dic_identifiant,debut_pas, lot_tax_code, lot_std_code,type_de_quantite ")
+			ORDER BY ope_dic_identifiant,debut_pas, lot_tax_code, lot_std_code,type_de_quantite ",
+        drv="PostgreSQL")
   }
   # if some samples overlap between the current year and the year arround the current year,
   # then the calculation will have hampered our numbers of a small amount
@@ -970,6 +973,7 @@
 #' @author Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
 #' @export
 fun_report_mig_mult <- function(time.sequence, datasub,negative=FALSE) {
+  sqldf.options<-get("sqldf.options",envir_stacomi)
   df.ts=data.frame(debut_pas=time.sequence,
 	  fin_pas=time.sequence+as.difftime(1,units="days"),
 	  ts_id=strftime(time.sequence,format="%j"),stringsAsFactors =FALSE)
@@ -977,7 +981,7 @@
   datasub1<-merge(df.ts,datasub,by="ts_id")
   # ci dessous pour faire du group by c'est quand meme bien de passer par sqldf
   if (negative){
-	datasub2<-sqldf::sqldf("SELECT  debut_pas,
+	datasub2<-sqldf::sqldf(x="SELECT  debut_pas,
 			fin_pas,
 			sum(value) as value,
 			type_de_quantite,
@@ -1001,9 +1005,10 @@
 			FROM datasub1 
 			WHERE value<0
 			GROUP BY ope_dic_identifiant,lot_tax_code, lot_std_code, lot_methode_obtention, debut_pas,fin_pas,type_de_quantite
-			ORDER BY ope_dic_identifiant,debut_pas, lot_tax_code, lot_std_code,type_de_quantite ")
+			ORDER BY ope_dic_identifiant,debut_pas, lot_tax_code, lot_std_code,type_de_quantite ",
+        drv="PostgreSQL")
   } else {
-	datasub2<-sqldf::sqldf("SELECT  debut_pas,
+	datasub2<-sqldf::sqldf(x="SELECT  debut_pas,
 			fin_pas,
 			sum(value) as value,
 			type_de_quantite,
@@ -1013,7 +1018,8 @@
 			lot_methode_obtention
 			FROM datasub1 
 			GROUP BY ope_dic_identifiant,lot_tax_code, lot_std_code, lot_methode_obtention, debut_pas,fin_pas,type_de_quantite
-			ORDER BY ope_dic_identifiant,debut_pas, lot_tax_code, lot_std_code,type_de_quantite")
+			ORDER BY ope_dic_identifiant,debut_pas, lot_tax_code, lot_std_code,type_de_quantite",
+        drv="PostgreSQL")
   }
   stopifnot(all.equal(sum(datasub$value,na.rm=TRUE),sum(datasub2$value,na.rm=TRUE)))
   datasub3<-reshape2::dcast(datasub2, debut_pas+fin_pas+ope_dic_identifiant+lot_tax_code+lot_std_code+type_de_quantite~lot_methode_obtention,value.var="value")

Modified: pkg/stacomirtools/DESCRIPTION
===================================================================
--- pkg/stacomirtools/DESCRIPTION	2017-06-21 06:21:15 UTC (rev 409)
+++ pkg/stacomirtools/DESCRIPTION	2017-06-21 15:19:14 UTC (rev 410)
@@ -5,7 +5,9 @@
 Authors at R: c(person("Cedric", "Briand", role = c("aut", "cre"), email = "cedric.briand00 at gmail.com"))
 Author: Cedric Briand [aut, cre]
 Maintainer: Cedric Briand <cedric.briand00 at gmail.com>
-Description: S4 class wrappers 	for ODBC connection.
+Description: This package provides S4 class wrappers for the ODBC connection, it also provides some 
+utilities to paste small datasets to clipboard, rename columns. It is used by the package stacomiR for
+connections to the database. 
 License: GPL (>= 2)
 Collate:
     'ConnectionODBC.r'

Modified: pkg/stacomirtools/R/ConnectionODBC.r
===================================================================
--- pkg/stacomirtools/R/ConnectionODBC.r	2017-06-21 06:21:15 UTC (rev 409)
+++ pkg/stacomirtools/R/ConnectionODBC.r	2017-06-21 15:19:14 UTC (rev 410)
@@ -1,13 +1,4 @@
-# Nom fichier :        ConnectionODBC (classe)
-# Organisme :          IAV
-# Auteur :             Cedric Briand
-# Contact :            cedric.briand"at"eptb-vilaine.fr
-# Date de creation :   06/02/2007 10:58:37
-# Etat :               OK
-# Description          Classe de connexion a la base de donnee
-#**********************************************************************
 
-#validation function
 validity_ODBC=function(object)
 {
 	rep1= class(object at baseODBC[1])=="Character"

Modified: pkg/stacomirtools/R/RequeteODBC.r
===================================================================
--- pkg/stacomirtools/R/RequeteODBC.r	2017-06-21 06:21:15 UTC (rev 409)
+++ pkg/stacomirtools/R/RequeteODBC.r	2017-06-21 15:19:14 UTC (rev 410)
@@ -9,17 +9,19 @@
 #' @slot sql="character"
 #' @slot query="data.frame"
 #' @slot open=logical is the connection left open after the request ?
-#' @expamples object=new("RequeteODBC")
+#' @examples object=new("RequeteODBC")
 setClass(Class="RequeteODBC",
 		representation= representation(sql="character",query="data.frame",open="logical"),
 		prototype = list(silent=TRUE,open=FALSE),
 		contains="ConnectionODBC")
 
 #' connect method loads a request to the database and returns either an error or a data.frame
-#' @note assign("showmerequest",1,envir=envir_stacomi) permet d'afficher toutes les requetes passant par la classe connect
+#' @note assign("showmerequest",1,envir=envir_stacomi) allows to print all queries passing on the class connect
 #' @return An object of class RequeteODBC
 #' @author Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
 #' @expamples 
+#' showClass("RequeteODBC")
+#' \dontrun{
 #' object=new("RequeteODBC")
 #' object at open=TRUE
 #' object at baseODBC=baseODBC
@@ -27,6 +29,27 @@
 #' object<-connect(object)
 #' odbcClose(object at connection)
 #' odbcCloseAll()
+#'   object=new("RequeteODBC")
+#'   object at open=TRUE 
+#'   ## this will leave the connection open, 
+#'   ## by default it closes after the query is sent
+#'   ## the following will work only if you have configured and ODBC link
+#'   object at baseODBC=c("myODBCconnection","myusername","mypassword")
+#'   object at sql= "select * from mytable limit 100"
+#'   object<-connect(object)
+#'   odbcClose(object at connection)
+#'   envir_stacomi=new.env()
+#'   ## While testing if you want to see the output of sometimes complex queries generated by the program
+#'   assign("showmerequest",1,envir_stacomi) 
+#'   ## You can assign any values (here 1)
+#'   ## just tests the existence of "showmerequest" in envir_stacomi
+#'   object=new("RequeteODBC")
+#'   object at baseODBC=c("myODBCconnection","myusername","mypassword")
+#'   object at sql= "select * from mytable limit 100"
+#'   object<-connect(object)
+#'  ## the connection is already closed, the query is printed
+#'}
+
 setMethod("connect",signature=signature("RequeteODBC"),definition=function(object) {     
 			msg1<-gettext("ODBC error =>you have to define a vector baseODBC with the ODBC link name, user and password")
 			msg2<-gettext("connection trial :")



More information about the Stacomir-commits mailing list