[Stacomir-commits] r391 - in pkg/stacomir: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jun 9 15:44:20 CEST 2017


Author: briand
Date: 2017-06-09 15:44:19 +0200 (Fri, 09 Jun 2017)
New Revision: 391

Added:
   pkg/stacomir/man/getdbname.Rd
Modified:
   pkg/stacomir/R/BilanAgedemer.r
   pkg/stacomir/R/BilanMigration.r
   pkg/stacomir/R/BilanMigrationInterAnnuelle.r
   pkg/stacomir/R/Bilan_carlot.r
   pkg/stacomir/R/Bilan_poids_moyen.r
   pkg/stacomir/R/data.r
   pkg/stacomir/R/utilitaires.r
   pkg/stacomir/man/bfDF.Rd
   pkg/stacomir/man/write_database-BilanAgedemer-method.Rd
   pkg/stacomir/man/write_database-BilanMigration-method.Rd
   pkg/stacomir/man/write_database-Bilan_poids_moyen-method.Rd
Log:
Correction connection problem when database name is not standard in graphical interface

Modified: pkg/stacomir/R/BilanAgedemer.r
===================================================================
--- pkg/stacomir/R/BilanAgedemer.r	2017-06-09 11:48:50 UTC (rev 390)
+++ pkg/stacomir/R/BilanAgedemer.r	2017-06-09 13:44:19 UTC (rev 391)
@@ -349,17 +349,19 @@
 #' into the tj_caracteristiquelot_car table in the user's scheme
 #' 
 #' The sea age caracteristic is calculated from the mesured or calculated size of salmon and with a size/age rule
-#' defined by the user  
+#' defined by the user . the name of the database is retreived from the odbc link
+#' defined in calcmig.csv
 #' @param object an object of class \link{BilanAgedemer-class}
 #' @param silent : Default FALSE, if TRUE the program should no display messages.
-#' @param dbname : the name of the database, defaults to "bd_contmig_nat"
 #' @author Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
 #' @export
-setMethod("write_database",signature=signature("BilanAgedemer"),definition=function(object,silent=TRUE,dbname="bd_contmig_nat"){
+setMethod("write_database",signature=signature("BilanAgedemer"),definition=function(object,silent=TRUE){
 			# dbname="bd_contmig_nat"
 			bilan_adm<-object
 			host=get("sqldf.options",envir=envir_stacomi)["sqldf.host"]
 			port=get("sqldf.options",envir=envir_stacomi)["sqldf.port"]		
+			# getting the database name
+			dbname<-getdbname()		
 			calcdata<-bilan_adm at calcdata[["data"]]	
 			data_in_base<-bilan_adm at data
 			if (nrow(calcdata)==0) {   

Modified: pkg/stacomir/R/BilanMigration.r
===================================================================
--- pkg/stacomir/R/BilanMigration.r	2017-06-09 11:48:50 UTC (rev 390)
+++ pkg/stacomir/R/BilanMigration.r	2017-06-09 13:44:19 UTC (rev 391)
@@ -578,12 +578,12 @@
 #' by this function.  
 #' @param object an object of class \code{\linkS4class{BilanMigration}}
 #' @param silent : TRUE to avoid messages
-#' @param dbname : the name of the database, defaults to "bd_contmig_nat"
 #' @param check_for_bjo : do you want to check if data are already present in the bjo table, and delete them,
 #' this param was added otherwise connect method when called from BilanMigrationInterAnnuelle runs in loops
 #' @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. The name of the database
-#' is not passed in odbc link, here defaults to "bd_contmig_nat"
+#' is retrieved from the odbc link
+#' 
 #' @author Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
 #' @examples 
 #' \dontrun{
@@ -593,13 +593,15 @@
 #' write_database(bilanMigration=bM_Arzal,silent=FALSE)
 #' }
 #' @export
-setMethod("write_database",signature=signature("BilanMigration"),definition=function(object,silent=TRUE,dbname="bd_contmig_nat",check_for_bjo=TRUE){
+setMethod("write_database",signature=signature("BilanMigration"),definition=function(object,silent=TRUE,check_for_bjo=TRUE){
 			# dbname="bd_contmig_nat";host="localhost";silent=FALSE;port=5432
 			# object=bM
 			#host : the host for sqldf, defaults to "localhost"
 			 #port : the port, defaults to 5432
 			host=get("sqldf.options",envir=envir_stacomi)["sqldf.host"]
 			port=get("sqldf.options",envir=envir_stacomi)["sqldf.port"]		
+			# getting the database name
+			dbname<-getdbname()			
 			bilanMigration<-object
 			if (class(bilanMigration)!="BilanMigration") stop("the bilanMigration should be of class BilanMigration")
 			if (class(silent)!="logical") stop("the silent argument should be a logical")
@@ -655,6 +657,7 @@
 			# check = FALSE tells the method not to check for missing data (we don't want that check when the
 			# write database is called from the bilanMigration class
 			if (check_for_bjo) bil=connect(bil,silent=silent,check=FALSE)
+
 			
 			hconfirm=function(h,...){			
 				# suppression des donnees actuellement presentes dans la base
@@ -707,6 +710,7 @@
 				sql<-stringr::str_c("INSERT INTO ",get("sch",envir=envir_stacomi),"t_bilanmigrationjournalier_bjo (",			
 						"bjo_dis_identifiant,bjo_tax_code,bjo_std_code,bjo_annee,bjo_jour,bjo_valeur,bjo_labelquantite,bjo_horodateexport,bjo_org_code)",
 						" SELECT * FROM  aat_bilanmigrationjournalier_bjo;")
+				
 				invisible(utils::capture.output(
 								sqldf::sqldf(x=sql,
 										drv="PostgreSQL",

Modified: pkg/stacomir/R/BilanMigrationInterAnnuelle.r
===================================================================
--- pkg/stacomir/R/BilanMigrationInterAnnuelle.r	2017-06-09 11:48:50 UTC (rev 390)
+++ pkg/stacomir/R/BilanMigrationInterAnnuelle.r	2017-06-09 13:44:19 UTC (rev 391)
@@ -171,7 +171,8 @@
 	} # end for loop to write new bilans
 	# reloading everything
 	object at data<-fn_connect()			
-	compared_numbers<-fn_check()		
+	compared_numbers<-fn_check()
+	
 } # end if any...
 
 #-------------------------------------------------------------------------------------

Modified: pkg/stacomir/R/Bilan_carlot.r
===================================================================
--- pkg/stacomir/R/Bilan_carlot.r	2017-06-09 11:48:50 UTC (rev 390)
+++ pkg/stacomir/R/Bilan_carlot.r	2017-06-09 13:44:19 UTC (rev 391)
@@ -226,6 +226,7 @@
 			} else {      
 				if (!silent) funout(gettext("You need to launch computation first, clic on calc\n",domain="R-stacomiR"),arret=TRUE)
 			}
+			name_param<-bilan_carlot
 			if (plot.type==1){		
 				g<-ggplot(bilan_carlot at data,aes(x=car_valeur_quantitatif))
 				g<-g+stat_density(aes(ymax = ..density..,  ymin = -..density..),

Modified: pkg/stacomir/R/Bilan_poids_moyen.r
===================================================================
--- pkg/stacomir/R/Bilan_poids_moyen.r	2017-06-09 11:48:50 UTC (rev 390)
+++ pkg/stacomir/R/Bilan_poids_moyen.r	2017-06-09 13:44:19 UTC (rev 391)
@@ -542,10 +542,9 @@
 #' Function to write data to the stacomi database for \link{Bilan_poids_moyen-class}
 #' 
 #' Data will be written in tj_coefficientconversion_coe table, if the class retrieves some data
-#' from the database, those will be deleted first.
+#' from the database, those will be deleted first. 
 #' @param object An object of class \link{Bilan_poids_moyen-class}
 #' @param silent Boolean, if TRUE, information messages are not displayed
-#' @param dbname default "bd_contmig_nat"
 #' @return An object of class \link{Bilan_poids_moyen-class}
 #' @author Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
 #' @export
@@ -553,6 +552,8 @@
 			#silent=FALSE;dbname="bd_contmig_nat";host="localhost";port=5432
 			host=get("sqldf.options",envir=envir_stacomi)["sqldf.host"]
 			port=get("sqldf.options",envir=envir_stacomi)["sqldf.port"]		
+			# getting the database name
+			dbname<-getdbname()		
 			bilPM<-object
 			if (!"import_coe"%in% names(bilPM at calcdata)) funout(gettext("Attention, you must fit a model before trying to write the predictions in the database",domain="R-stacomiR"),arret=TRUE)
 			# first delete existing data from the database

Modified: pkg/stacomir/R/data.r
===================================================================
--- pkg/stacomir/R/data.r	2017-06-09 11:48:50 UTC (rev 390)
+++ pkg/stacomir/R/data.r	2017-06-09 13:44:19 UTC (rev 391)
@@ -106,13 +106,13 @@
 
 #' Overview of the fishway operation at Arzal in (Vilaine France).
 #' 
-#' This data corresponds to the data collected at the vertical slot fishway
+#' This dataset corresponds to the data collected at the vertical slot fishway
 #' in 2015, the fishway is working daily with a cycle depending on tide. This dataset
-#' is used to show an example of acdetailed output for an object of class \link{BilanFonctionnementDF-class} with data loaded
+#' is used to show an example of detailed output for an object of class \link{BilanFonctionnementDF-class} with data loaded
 #'
 #' @format An object of class BilanFonctionnementDF with 4 slots:
 #' \describe{
-#' #'   \item{data}{ A dataframe with 4261 obs. of  7 variables
+#'   \item{data}{ A dataframe with 4261 obs. of  7 variables
 #' 			\describe{
 #'   			\item{per_dis_identifiant}{The number of the DF}
 #'   			\item{per_date_debut}{Starting time a POSIXct}
@@ -130,7 +130,7 @@
 #'        }	
 #'   \item{df}{the \code{RefDF} object with 3 slots filled with data corresponding to the iav postgres schema}
 #'   \item{horodatedebut}{the \code{RefHorodate} with horodate set for starting date}
-#'   \item{horodatefin}{the \code{RefHorodate} with horodate set for ending date} #'   
+#'   \item{horodatefin}{the \code{RefHorodate} with horodate set for ending date}'   
 #' }
 #' @keywords data
 "bfDF"

Modified: pkg/stacomir/R/utilitaires.r
===================================================================
--- pkg/stacomir/R/utilitaires.r	2017-06-09 11:48:50 UTC (rev 390)
+++ pkg/stacomir/R/utilitaires.r	2017-06-09 13:44:19 UTC (rev 391)
@@ -406,4 +406,18 @@
 	bonordre<-match(cs$color,levels(cs$color))
 	cs$color = factor(cs$color,levels(cs$color)[bonordre])
 	return(cs)
+}
+
+
+#' Retreives the dbnames from a connection using "baseOBC"
+#' @return A string with the name of the database
+getdbname<-function(){
+	req<-new("RequeteODBC")
+	req at baseODBC<-get("baseODBC",envir=envir_stacomi)
+	req at sql<-str_c("select * from ",get("sch",envir=envir_stacomi),"t_bilanmigrationjournalier_bjo limit 1")
+	res<-connect(req)
+	odbc<-res at connection
+	aa<-strsplit(attributes(odbc)$connection.string,";")
+	dbname=gsub("DATABASE=","",aa[[1]][2])
+	return(dbname)
 }
\ No newline at end of file

Modified: pkg/stacomir/man/bfDF.Rd
===================================================================
--- pkg/stacomir/man/bfDF.Rd	2017-06-09 11:48:50 UTC (rev 390)
+++ pkg/stacomir/man/bfDF.Rd	2017-06-09 13:44:19 UTC (rev 391)
@@ -6,7 +6,7 @@
 \title{Overview of the fishway operation at Arzal in (Vilaine France).}
 \format{An object of class BilanFonctionnementDF with 4 slots:
 \describe{
-#'   \item{data}{ A dataframe with 4261 obs. of  7 variables
+  \item{data}{ A dataframe with 4261 obs. of  7 variables
 			\describe{
   			\item{per_dis_identifiant}{The number of the DF}
   			\item{per_date_debut}{Starting time a POSIXct}
@@ -24,15 +24,15 @@
        }	
   \item{df}{the \code{RefDF} object with 3 slots filled with data corresponding to the iav postgres schema}
   \item{horodatedebut}{the \code{RefHorodate} with horodate set for starting date}
-  \item{horodatefin}{the \code{RefHorodate} with horodate set for ending date} #'   
+  \item{horodatefin}{the \code{RefHorodate} with horodate set for ending date}'   
 }}
 \usage{
 bfDF
 }
 \description{
-This data corresponds to the data collected at the vertical slot fishway
+This dataset corresponds to the data collected at the vertical slot fishway
 in 2015, the fishway is working daily with a cycle depending on tide. This dataset
-is used to show an example of acdetailed output for an object of class \link{BilanFonctionnementDF-class} with data loaded
+is used to show an example of detailed output for an object of class \link{BilanFonctionnementDF-class} with data loaded
 }
 \keyword{data}
 

Added: pkg/stacomir/man/getdbname.Rd
===================================================================
--- pkg/stacomir/man/getdbname.Rd	                        (rev 0)
+++ pkg/stacomir/man/getdbname.Rd	2017-06-09 13:44:19 UTC (rev 391)
@@ -0,0 +1,15 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/utilitaires.r
+\name{getdbname}
+\alias{getdbname}
+\title{Retreives the dbnames from a connection using "baseOBC"}
+\usage{
+getdbname()
+}
+\value{
+A string with the name of the database
+}
+\description{
+Retreives the dbnames from a connection using "baseOBC"
+}
+

Modified: pkg/stacomir/man/write_database-BilanAgedemer-method.Rd
===================================================================
--- pkg/stacomir/man/write_database-BilanAgedemer-method.Rd	2017-06-09 11:48:50 UTC (rev 390)
+++ pkg/stacomir/man/write_database-BilanAgedemer-method.Rd	2017-06-09 13:44:19 UTC (rev 391)
@@ -6,19 +6,17 @@
 \title{Command line method to write the caracteristic "sea age" (car_par_code='A124')
 into the tj_caracteristiquelot_car table in the user's scheme}
 \usage{
-\S4method{write_database}{BilanAgedemer}(object, silent = TRUE,
-  dbname = "bd_contmig_nat")
+\S4method{write_database}{BilanAgedemer}(object, silent = TRUE)
 }
 \arguments{
 \item{object}{an object of class \link{BilanAgedemer-class}}
 
 \item{silent}{: Default FALSE, if TRUE the program should no display messages.}
-
-\item{dbname}{: the name of the database, defaults to "bd_contmig_nat"}
 }
 \description{
 The sea age caracteristic is calculated from the mesured or calculated size of salmon and with a size/age rule
-defined by the user
+defined by the user . the name of the database is retreived from the odbc link
+defined in calcmig.csv
 }
 \author{
 Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}

Modified: pkg/stacomir/man/write_database-BilanMigration-method.Rd
===================================================================
--- pkg/stacomir/man/write_database-BilanMigration-method.Rd	2017-06-09 11:48:50 UTC (rev 390)
+++ pkg/stacomir/man/write_database-BilanMigration-method.Rd	2017-06-09 13:44:19 UTC (rev 391)
@@ -7,15 +7,13 @@
 t_bilanmigrationjournalier_bjo table}
 \usage{
 \S4method{write_database}{BilanMigration}(object, silent = TRUE,
-  dbname = "bd_contmig_nat", check_for_bjo = TRUE)
+  check_for_bjo = TRUE)
 }
 \arguments{
 \item{object}{an object of class \code{\linkS4class{BilanMigration}}}
 
 \item{silent}{: TRUE to avoid messages}
 
-\item{dbname}{: the name of the database, defaults to "bd_contmig_nat"}
-
 \item{check_for_bjo}{: do you want to check if data are already present in the bjo table, and delete them,
 this param was added otherwise connect method when called from BilanMigrationInterAnnuelle runs in loops}
 }
@@ -26,7 +24,7 @@
 \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. The name of the database
-is not passed in odbc link, here defaults to "bd_contmig_nat"
+is retrieved from the odbc link
 }
 \examples{
 \dontrun{

Modified: pkg/stacomir/man/write_database-Bilan_poids_moyen-method.Rd
===================================================================
--- pkg/stacomir/man/write_database-Bilan_poids_moyen-method.Rd	2017-06-09 11:48:50 UTC (rev 390)
+++ pkg/stacomir/man/write_database-Bilan_poids_moyen-method.Rd	2017-06-09 13:44:19 UTC (rev 391)
@@ -12,8 +12,6 @@
 \item{object}{An object of class \link{Bilan_poids_moyen-class}}
 
 \item{silent}{Boolean, if TRUE, information messages are not displayed}
-
-\item{dbname}{default "bd_contmig_nat"}
 }
 \value{
 An object of class \link{Bilan_poids_moyen-class}



More information about the Stacomir-commits mailing list