[Stacomir-commits] r574 - in pkg/stacomirtools: . R dev man tests/testthat

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Nov 2 18:53:43 CET 2021


Author: briand
Date: 2021-11-02 18:53:43 +0100 (Tue, 02 Nov 2021)
New Revision: 574

Added:
   pkg/stacomirtools/MD5
   pkg/stacomirtools/R/zzz.R
   pkg/stacomirtools/man/stacomirtools-deprecated.Rd
   pkg/stacomirtools/man/stacomirtools.Rd
Modified:
   pkg/stacomirtools/DESCRIPTION
   pkg/stacomirtools/NAMESPACE
   pkg/stacomirtools/R/ConnectionDB.R
   pkg/stacomirtools/R/ConnectionODBC.R
   pkg/stacomirtools/R/RequeteDB.R
   pkg/stacomirtools/R/RequeteODBC.R
   pkg/stacomirtools/R/utilities.R
   pkg/stacomirtools/README.Rmd
   pkg/stacomirtools/README.md
   pkg/stacomirtools/dev/03_deploy.R
   pkg/stacomirtools/tests/testthat/test-00-connectiondb.R
   pkg/stacomirtools/tests/testthat/test-02-requeteDB.R
Log:
setting options for connection in the package 

Modified: pkg/stacomirtools/DESCRIPTION
===================================================================
--- pkg/stacomirtools/DESCRIPTION	2021-10-26 07:05:49 UTC (rev 573)
+++ pkg/stacomirtools/DESCRIPTION	2021-11-02 17:53:43 UTC (rev 574)
@@ -15,7 +15,7 @@
 Collate: 'ConnectionODBC.R' 'RequeteODBC.R' 'RequeteODBCwhere.R'
         'RequeteODBCwheredate.R' 'utilities.R' 'stacomirtools.R'
         'stacomirtools-package.R''ConnectionDB.R' 'RequeteDB.R' 'RequeteDBwhere.R'
-        'RequeteDBwheredate.R'
+        'RequeteDBwheredate.R' 'zzz.R'
 LazyLoad: yes
 Depends: RODBC, DBI, pool
 Imports: 
@@ -23,7 +23,7 @@
     xtable,
     utils,
     RPostgres
-Suggests: testthat, stacomiR
+Suggests: testthat
 Repository: CRAN
 Repository/R-Forge/Project: stacomir
 Repository/R-Forge/Revision: 540

Added: pkg/stacomirtools/MD5
===================================================================
--- pkg/stacomirtools/MD5	                        (rev 0)
+++ pkg/stacomirtools/MD5	2021-11-02 17:53:43 UTC (rev 574)
@@ -0,0 +1,27 @@
+fa9df54055b2032d5a971bceac2e57b2 *DESCRIPTION
+46ca8b5c60e7b343526f863e3383a495 *NAMESPACE
+0256217bf4c49dd564d5b6e1fbefc069 *R/ConnectionODBC.r
+b5f23b148a184a2aa880b05504894fb9 *R/RequeteODBC.r
+329e3f8f59007636c561dfcf7848d975 *R/RequeteODBCwhere.r
+dfaa6ccffc92532b4b0abfd20841f157 *R/RequeteODBCwheredate.r
+c37a5d05f585a69125223776367fcefa *R/stacomirtools-package.R
+b0bfb4ceec374210f2e95e49f20a909f *R/stacomirtools.r
+e84ff24010ffb874615a6f5f141c06c2 *R/utilities.r
+d474e5cee5a54769491b2c79b282dc37 *inst/config/test.R
+72c7e0ad2273b92f1f77219f247cdb4e *man/ConnectionODBC-class.Rd
+4dda593b1756df9096a70354ca29b1cc *man/RequeteODBC-class.Rd
+b5c8b7c5118da048ae0d185a819749e6 *man/RequeteODBCwhere-class.Rd
+e693297f1f462f5f95345141291165a4 *man/RequeteODBCwheredate-class.Rd
+ef718e3e796c67ed0463a84f89e96732 *man/chnames.Rd
+ccabea0c56953f73c3eded3cb4e17643 *man/connect-methods.Rd
+dc0107ac7aefb1012f22cf08ec32ab0c *man/ex.Rd
+b3184bbc1ac0607a448c7b8a0813ffed *man/funhtml.Rd
+3686d96a799de52cd74b6b1c49bd37ac *man/funout.Rd
+b64d126bd9449f49a14ac6acf113551e *man/induk.Rd
+6ec40b12eaa972ff9830c1c0c1ed797a *man/is.even.Rd
+d0fbab358dadbdd86164da1c48e6fce3 *man/is.odd.Rd
+3bd4ede162d0166b0d21f038c208a106 *man/killfactor.Rd
+82addf039bd07a44158f3baeea1c5686 *man/stacomirtools-package.Rd
+a5e423b286a06371030fce688e31741e *man/tab2df.Rd
+2519d39193a51edcb94b81fdee35fe43 *tests/testthat.R
+364d22588a8444e139d0c99e4f2f6487 *tests/testthat/test-00.R

Modified: pkg/stacomirtools/NAMESPACE
===================================================================
--- pkg/stacomirtools/NAMESPACE	2021-10-26 07:05:49 UTC (rev 573)
+++ pkg/stacomirtools/NAMESPACE	2021-11-02 17:53:43 UTC (rev 574)
@@ -4,7 +4,6 @@
 export(connect)
 export(ex)
 export(funhtml)
-export(funout)
 export(induk)
 export(is.even)
 export(is.odd)

Modified: pkg/stacomirtools/R/ConnectionDB.R
===================================================================
--- pkg/stacomirtools/R/ConnectionDB.R	2021-10-26 07:05:49 UTC (rev 573)
+++ pkg/stacomirtools/R/ConnectionDB.R	2021-11-02 17:53:43 UTC (rev 574)
@@ -8,14 +8,24 @@
 	rep3 <- length(object at port)==1
 	rep4 <- length(object at user)==1	
 	rep5 <- length(object at password)==1
+	rep6 <- !is.null(object at dbname)
+	rep7 <- !is.null(object at host)
+	rep8 <- !is.null(object at port)
+	rep9 <- !is.null(object at user)
+	rep10 <- !is.null(object at password)
 	
-	return(ifelse(rep1 & rep2 & rep3 & rep4 & rep5  ,TRUE,
+	return(ifelse(rep1 & rep2 & rep3 & rep4 & rep5 & rep6 & rep7 & rep8 & rep9 & rep10  ,TRUE,
 					c(gettext("dbname should be of length 1"),
 							gettext("host should be of length 1"),
 							gettext("port should be of length 1"),
 							gettext("user should be of length 1"),
-							gettext("password should be of length 1"))[
-							!c(rep1, rep2, rep3, rep4, rep5)]))
+							gettext("password should be of length 1"),
+							gettext("dbname should not be NULL, did you forget to set dbname ? hint use : options('stacomiR.dbname'='bd_contmig_nat')"),
+							gettext("host should not be NULL, did you forget to set host ? hint use: options('stacomiR.host'='localhost')"),
+							gettext("port should not be NULL, did you forget to set port ?  hint use: ('stacomiR.port'='5432')"),
+							gettext("user should not be NULL, did you forget to set user ? hint use : options('stacomiR.user'='myuser')"),
+							gettext("password should not be NULL, did you forget to set dbname ? hint use : options('stacomiR.password'='mypassword')"))[
+							!c(rep1, rep2, rep3, rep4, rep5,rep6, rep7, rep8, rep9, rep10)]))
 }
 
 #' @title ConnectionDB class 
@@ -80,18 +90,22 @@
 #' pool::poolClose(object at connection)
 #' }
 setMethod("connect", signature=signature("ConnectionDB"), 
-		definition=function(object, base=NULL) {     
+		definition=function(object, base=NULL) {  
+			#browser()
 			if (!is.null(base)) {
 				object at dbname <- base[1]
-				object at host=base[2]
-				object at port=base[3]
-				object at user=base[4]
-				object at password=base[5]
+				object at host <- base[2]
+				object at port <- base[3]
+				object at user <- base[4]
+				object at password <- base[5]
+			} else if (options("stacomiR.user")[[1]]!=""){
+				object at dbname <- options("stacomiR.dbname")[[1]]
+				object at host <- options("stacomiR.host")[[1]]
+				object at port <- options("stacomiR.port")[[1]]
+				object at user <- options("stacomiR.user")[[1]]
+				object at password <- options("stacomiR.password")[[1]]
 			}
-			test <- validObject(object, test=TRUE)
-			if (is.character(test)) {
-				funout(test, arret=TRUE)
-			}
+			validObject(object, test=TRUE)
 			
 			
 			currentConnection <- pool::dbPool(drv = RPostgres::Postgres(), 
@@ -105,7 +119,7 @@
 			
 #			if (!exists("odbcConnect")) {
 #				if (exists("envir_stacomi")){
-#					funout("The RODBC library is necessary, please load the package",arret=TRUE)
+#					stop("The RODBC library is necessary, please load the package")
 #				} else	  {
 #					stop("the RODBC library is necessary, please load the package")
 #				}

Modified: pkg/stacomirtools/R/ConnectionODBC.R
===================================================================
--- pkg/stacomirtools/R/ConnectionODBC.R	2021-10-26 07:05:49 UTC (rev 573)
+++ pkg/stacomirtools/R/ConnectionODBC.R	2021-11-02 17:53:43 UTC (rev 574)
@@ -55,60 +55,33 @@
 setMethod("connect",signature=signature("ConnectionODBC"),definition=function(object) {
 			.Deprecated(new= "ConnectionDB", old="ConnectionODBC")			
 			if (length(object at baseODBC)!=3)  {
-				if (exists("baseODBC",envir=envir_stacomi)){ 
-					object at baseODBC<-get("baseODBC",envir=envir_stacomi) 
-				} else {
-					if (exists("envir_stacomi")){# the program is called within stacomiR
-						funout(gettext("You need to define a baseODBC vector with the 'ODBC' link, the user and the password\n"),arret=TRUE)
-					} else	  {
-						stop("you need to define a vector baseODBC with the 'ODBC' link, user and password")
-					}
-				}
-			}
+				object at baseODBC <- c(
+						options("stacomiR.ODBClink")[[1]],
+						options("stacomiR.user")[[1]],
+						options("stacomiR.password")[[1]]
+				)				
+			} 			
+			
 			e=expression(channel <-odbcConnect(object at baseODBC[1],
 							uid = object at baseODBC[2],
 							pwd = object at baseODBC[3],
 							case = "tolower",
 							believeNRows = FALSE))
-			if (!exists("odbcConnect")) {
-				if (exists("envir_stacomi")){
-					funout("The RODBC library is necessary, please load the package",arret=TRUE)
-				} else	  {
-					stop("the RODBC library is necessary, please load the package")
-				}
-			}
+
 			if (!object at silent) {
-				if (exists("envir_stacomi")){
 					print(paste("connection trial, warning this class should only be used for test: ",object at baseODBC[1]))
-				} else {
-					print(paste("connection trial, warning this class should only be used for test: ",object at baseODBC[1]))
-				}
 			}	
-			# sends the result of a trycatch connection in the
-			#l'object (current connection), e.g. a character vector
-			connection_error<-if (exists("envir_stacomi")){
-						error=paste(gettext("Connection failed :\n",object at baseODBC[1]))
-					} else {
-						error="impossible connection"
-					}
+			connection_error <- paste(gettext("Connection failed :\n",object at baseODBC[1]))
+
 			currentConnection<-tryCatch(eval(e), error=connection_error) 
 			if (class(currentConnection)=="RODBC") {
-				if (!object at silent){
-					if(exists("envir_stacomi")){
+				if (!object at silent){				
 						print(gettext("Connection successful"))
-					} else {
-						print("connection successful")
-					}
 				} 
-				object at connection=currentConnection  # an object S3 RODBC
-				if(exists("envir_stacomi")){
-					state<-"Connection in progress"
-				} else {
-					state<-"Connection in progress"
-				}
-				object at etat=state
+				object at connection <- currentConnection  # an object S3 RODBC
+				object at etat="Connection in progress"
 			} else {
-				funout(currentConnection)
+				cat(currentConnection)
 				object at etat=currentConnection # reporting error
 			}
 			return(object)

Modified: pkg/stacomirtools/R/RequeteDB.R
===================================================================
--- pkg/stacomirtools/R/RequeteDB.R	2021-10-26 07:05:49 UTC (rev 573)
+++ pkg/stacomirtools/R/RequeteDB.R	2021-11-02 17:53:43 UTC (rev 574)
@@ -57,37 +57,33 @@
 			msg4 <- gettext("connection successfull")
 			msg5 <- gettext("request trial")
 			msg6 <- gettext("success")
-			if (requireNamespace("stacomiR", quietly = TRUE)){
-				if (exists("envir_stacomi", where =asNamespace("stacomiR"), mode="environment")){
-					verbose <- exists("showmerequest",envir=envir_stacomi)
-				} else {
-					verbose <- FALSE
-				}
-			} else {
-				verbose <- FALSE
+			printqueries <- options("stacomiR.printqueries")[[1]]
+			if (is.null(printqueries)) printqueries <- FALSE
 				
-			}
+			 
+			
 			# The connection might already be opened, we will avoid to go through there !
 			if (is.null(object at connection)){ 						
 				# opening of connection
 				e=expression(channel <- connect(object, ...))
-				if (!object at silent) funout(paste(msg2, object at dbname, "\n"))
+				if (!object at silent) cat(paste(msg2, object at dbname, "\n"))
 				# send the result of a try catch expression in
 				#the Currentconnection object ie a character vector
 				object<-tryCatch(eval(e), error=paste(msg3 ,object at dbname)) 
 				# un object S3 RODBC
 				if (any(class(object at connection)=="Pool")) {
-					if (!object at silent) funout(msg4)
+					if (!object at silent) cat(msg4)
 					object at status <- msg4# success
 				} else {
 					object at status <- object at connection # report of the error
 					object at connection <- NULL
-					funout(msg3, arret=TRUE)
+					stop(msg3)
 				}
 				# sending the query
 			} 
-			if (!object at silent) funout(msg5) # query trial
-			if (verbose) print(object at sql)
+			if (!object at silent) cat(msg5) # query trial
+			if (printqueries) print(object at sql)
+			if (length(object at sql)==0) warnings("No sql query")
 			query <- data.frame() # otherwise, query called in the later expression is evaluated as a global variable by RCheck
 			e=expression(query<- dbGetQuery(object at connection,object at sql,errors=TRUE))
 			if (object at open) {
@@ -98,7 +94,7 @@
 				resultatRequete<-tryCatch(eval(e),error = function(e) e,finally=pool::poolClose(object at connection))
 			}
 			if (any(class(resultatRequete)=="data.frame")) {
-				if (!object at silent) funout(msg6)
+				if (!object at silent) cat(msg6)
 				object at query <- killfactor(query)    
 				object at status <- msg6
 			} else {
@@ -109,4 +105,17 @@
 			return(object)
 			
 		}
-)
\ No newline at end of file
+)
+
+#' generic query function for  
+#' @param object an object
+#' @param ... additional parameters passed to query
+setGeneric("getquery", def=function(object, ...) standardGeneric("getquery"))
+
+
+#' getquery retreives the result of the query from the object
+#' @param object an object of class RequeteDB
+#' @return A data frame
+setMethod("getquery",signature=signature("RequeteDB"),
+		definition=function(object) {
+			return(object at query)})

Modified: pkg/stacomirtools/R/RequeteODBC.R
===================================================================
--- pkg/stacomirtools/R/RequeteODBC.R	2021-10-26 07:05:49 UTC (rev 573)
+++ pkg/stacomirtools/R/RequeteODBC.R	2021-11-02 17:53:43 UTC (rev 574)
@@ -56,16 +56,10 @@
 			msg4<-gettext("connection successfull")
 			msg5<-gettext("request trial")
 			msg6<-gettext("success")
-			if (requireNamespace("stacomiR", quietly = TRUE)){
-				if (exists("envir_stacomi", where =asNamespace("stacomiR"), mode="environment")){
-					verbose<-exists("showmerequest",envir=envir_stacomi)
-				} else {
-					verbose <- FALSE
-				}
-			} else {
-				verbose <- FALSE
-				
-			}
+
+			printqueries <- options("stacomiR.printqueries")[[1]]
+			if (is.null(printqueries)) printqueries <- FALSE
+	
 			
 			# The connection might already be opened, we will avoid to go through there !
 			if (is.null(object at connection)){ 				
@@ -73,7 +67,7 @@
 					if (exists("baseODBC",envir=envir_stacomi)) {
 						object at baseODBC<-get("baseODBC",envir=envir_stacomi)  
 					} else {
-						funout(msg1,arret=TRUE)
+						stop(msg1)
 					}
 				}
 				# opening of 'ODBC' connection
@@ -82,25 +76,25 @@
 								pwd = object at baseODBC[3],
 								case = "tolower",
 								believeNRows = FALSE))
-				if (!object at silent) funout(paste(msg2,object at baseODBC[1],"\n"))
+				if (!object at silent) cat(paste(msg2,object at baseODBC[1],"\n"))
 				# send the result of a try catch expression in
 				#the Currentconnection object ie a character vector
 				object at connection<-tryCatch(eval(e), error=paste(msg3 ,object at baseODBC)) 
 				# un object S3 RODBC
 				if (class(object at connection)=="RODBC") {
-					if (!object at silent)funout(msg4)
+					if (!object at silent) cat(msg4)
 					object at etat=msg4# success
 				} else {
 					object at etat<-object at connection # report of the error
 					object at connection<-NULL
-					funout(msg3,arret=TRUE)
+					stop(msg3)
 				}
 				# sending the query
 			} 
-			if (!object at silent) funout(msg5) # query trial
-			if (verbose) print(object at sql)
-			query<-data.frame() # otherwise, query called in the later expression is evaluated as a global variable by RCheck
-			e=expression(query<-sqlQuery(object at connection,object at sql,errors=TRUE))
+			if (!object at silent) cat(msg5) # query trial
+			if (printqueries) print(object at sql)
+			query <- data.frame() # otherwise, query called in the later expression is evaluated as a global variable by RCheck
+			e <- expression(query<-sqlQuery(object at connection,object at sql,errors=TRUE))
 			if (object at open) {
 				# If we want to leave the connection open no finally clause
 				resultatRequete<-tryCatch(eval(e),error = function(e) e)
@@ -109,7 +103,7 @@
 				resultatRequete<-tryCatch(eval(e),error = function(e) e,finally=RODBC::odbcClose(object at connection))
 			}
 			if ((class(resultatRequete)=="data.frame")[1]) {
-				if (!object at silent) funout(msg6)
+				if (!object at silent) cat(msg6)
 				object at query=killfactor(query)    
 				object at etat=msg6
 			} else {

Modified: pkg/stacomirtools/R/utilities.R
===================================================================
--- pkg/stacomirtools/R/utilities.R	2021-10-26 07:05:49 UTC (rev 573)
+++ pkg/stacomirtools/R/utilities.R	2021-11-02 17:53:43 UTC (rev 574)
@@ -214,7 +214,7 @@
 #' tab2df(ftdf)
 #' 
 #' @export
-tab2df<-function(tab){
+tab2df <- function(tab){
 	if (length((attributes(tab)$dim))>2) stop("only works with tables of dim 2")
 	df=as.data.frame(matrix(as.vector(tab),nrow(tab),ncol(tab)))
 	rownames(df)<-attributes(tab)$row.vars[[1]]
@@ -221,13 +221,5 @@
 	colnames(df)<-attributes(tab)$col.vars[[1]]	
 	return(df)
 }
-#' Function loaded in this package to avoid errors, if the package is called without stacomiR
-#' @param text The text to display
-#' @param arret Boolean should the program stop
-#' @param wash FALSE only used when called from within stacomiR, and there is a widget interface,
-#' kept there for consistency 
-#' @author Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
-#' @export
-funout<-function(text,arret=FALSE,wash=FALSE){
-	if(arret) stop(text) else print(text,quote=FALSE)
-}
\ No newline at end of file
+
+

Added: pkg/stacomirtools/R/zzz.R
===================================================================
--- pkg/stacomirtools/R/zzz.R	                        (rev 0)
+++ pkg/stacomirtools/R/zzz.R	2021-11-02 17:53:43 UTC (rev 574)
@@ -0,0 +1,66 @@
+
+
+
+
+
+#' Stacomirtools options.
+#'
+#' @section Package options:
+#'
+#' stacomirtools uses the following [options()] to configure behaviour:
+#'
+#' \itemize{
+#'   \item `stacomiR.dbname`: databasename
+#'
+#'   \item `stacomiR.host`: the name of the host, often ["localhost"]
+#' 
+#'   \item `stacomiR.port`: the name of the port, most often ["5432"]
+#'    
+#'   \item `stacomiR.user`: a string with the user name e.g. ["postgres"]#'     
+#'
+#'   \item `stacomiR.password`: a string with the user password
+#'
+#'   \item `stacomiR.ODBClink`: a string with name of the ODBC link, default NULL
+#'
+#'   \item `stacomiR.path`: a string with the path to where some output are written  
+#'
+#'    \item `stacomiR.printqueries`: a boolean, default FALSE, with the side effect of printing queries to the console
+#' }
+#' @docType package
+#' @keywords internal
+#' @name stacomirtools
+"_PACKAGE"
+
+#' Deprecated Functions
+#'
+#' These functions are Deprecated in this release of devtools, they will be
+#' marked as Defunct and removed in a future version.
+#' @name stacomirtools-deprecated
+#' @keywords internal
+NULL
+
+
+stacomi_default_options <- list(
+		stacomiR.path = "~",
+		stacomiR.dbname = "bd_contmig_nat",
+		stacomiR.host ="localhost",
+		stacomiR.port = "5432",
+		stacomiR.user = "",
+		stacomiR.password = "",
+		stacomiR.ODBClink = NULL,
+		stacomiR.printqueries = FALSE
+)
+
+
+.onLoad <- function(...) {
+	op <- options()
+	toset <- !(names(stacomi_default_options) %in% names(op))
+	if (any(toset)) options(stacomi_default_options[toset])
+	
+	invisible()
+}
+
+
+
+
+

Modified: pkg/stacomirtools/README.Rmd
===================================================================
--- pkg/stacomirtools/README.Rmd	2021-10-26 07:05:49 UTC (rev 573)
+++ pkg/stacomirtools/README.Rmd	2021-11-02 17:53:43 UTC (rev 574)
@@ -27,10 +27,9 @@
 You can install the development version of stacomirtools like so:
 
 ``` r
-# TODO
-# install.packages("remotes")
-remotes::install_github(repo= "Remotes: gitlab::git at forgemia.inra.fr:stacomi/stacomirtools.git")
-
+#install.packages("remotes")
+#remotes::install_github(repo= "Remotes: gitlab::git at forgemia.inra.fr:stacomi/stacomirtools.git")
+install.packages("stacomirtools", repos="http://R-Forge.R-project.org")
 ```
 
 ## Example
@@ -37,7 +36,19 @@
 
 This is a basic example which shows you how to solve a common problem:
 
-```{r example}
+```{r example, eval=FALSE}
 library(stacomirtools)
-## basic example code
+options(list(
+						stacomi.path = "~",
+						stacomi.dbname = "bd_contmig_nat",
+						stacomi.host ="localhost",
+						stacomi.port = "5432",
+						stacomi.user = "mysuser",
+						stacomi.password = "mypassword",
+						stacomi.ODBClink = NULL,
+						stacomi.printqueries =FALSE
+				))
+req <- new("RequeteDB")
+req <- query(req)
+
 ```

Modified: pkg/stacomirtools/README.md
===================================================================
--- pkg/stacomirtools/README.md	2021-10-26 07:05:49 UTC (rev 573)
+++ pkg/stacomirtools/README.md	2021-11-02 17:53:43 UTC (rev 574)
@@ -18,9 +18,9 @@
 You can install the development version of stacomirtools like so:
 
 ``` r
-# TODO
-# install.packages("remotes")
-remotes::install_github(repo= "Remotes: gitlab::git at forgemia.inra.fr:stacomi/stacomirtools.git")
+#install.packages("remotes")
+#remotes::install_github(repo= "Remotes: gitlab::git at forgemia.inra.fr:stacomi/stacomirtools.git")
+install.packages("stacomirtools", repos="http://R-Forge.R-project.org")
 ```
 
 ## Example
@@ -29,8 +29,16 @@
 
 ``` r
 library(stacomirtools)
-#> Le chargement a nécessité le package : RODBC
-#> Le chargement a nécessité le package : DBI
-#> Le chargement a nécessité le package : pool
-## basic example code
+options(list(
+                        stacomi.path = "~",
+                        stacomi.dbname = "bd_contmig_nat",
+                        stacomi.host ="localhost",
+                        stacomi.port = "5432",
+                        stacomi.user = "mysuser",
+                        stacomi.password = "mypassword",
+                        stacomi.ODBClink = NULL,
+                        stacomi.printqueries =FALSE
+                ))
+req <- new("RequeteDB")
+req <- query(req)
 ```

Modified: pkg/stacomirtools/dev/03_deploy.R
===================================================================
--- pkg/stacomirtools/dev/03_deploy.R	2021-10-26 07:05:49 UTC (rev 573)
+++ pkg/stacomirtools/dev/03_deploy.R	2021-11-02 17:53:43 UTC (rev 574)
@@ -36,6 +36,6 @@
 ## This will build a tar.gz that can be installed locally, 
 ## sent to CRAN, or to a package manager
 devtools::build()
+devtools::install()
 
 
-

Added: pkg/stacomirtools/man/stacomirtools-deprecated.Rd
===================================================================
--- pkg/stacomirtools/man/stacomirtools-deprecated.Rd	                        (rev 0)
+++ pkg/stacomirtools/man/stacomirtools-deprecated.Rd	2021-11-02 17:53:43 UTC (rev 574)
@@ -0,0 +1,10 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/zzz.R
+\name{stacomirtools-deprecated}
+\alias{stacomirtools-deprecated}
+\title{Deprecated Functions}
+\description{
+These functions are Deprecated in this release of devtools, they will be
+marked as Defunct and removed in a future version.
+}
+\keyword{internal}

Added: pkg/stacomirtools/man/stacomirtools.Rd
===================================================================
--- pkg/stacomirtools/man/stacomirtools.Rd	                        (rev 0)
+++ pkg/stacomirtools/man/stacomirtools.Rd	2021-11-02 17:53:43 UTC (rev 574)
@@ -0,0 +1,45 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/zzz.R
+\docType{package}
+\name{stacomirtools}
+\alias{stacomirtools}
+\alias{stacomirtools-package}
+\title{Stacomirtools options.}
+\description{
+S4 class wrappers for the 'ODBC' and Pool dbi connection, also provides some utilities to paste small datasets to clipboard, rename columns. It is used by the package 'stacomiR' for connections to the database. Development versions of 'stacomiR' are available in R-forge.
+}
+\section{Package options}{
+
+
+stacomirtools uses the following [options()] to configure behaviour:
+
+\itemize{
+  \item `stacomiR.dbname`: databasename
+
+  \item `stacomiR.host`: the name of the host, often ["localhost"]
+
+  \item `stacomiR.port`: the name of the port, most often ["5432"]
+   
+  \item `stacomiR.user`: a string with the user name e.g. ["postgres"]#'     
+
+  \item `stacomiR.password`: a string with the user password
+
+  \item `stacomiR.ODBClink`: a string with name of the ODBC link, default NULL
+
+  \item `stacomiR.path`: a string with the path to where some output are written  
+
+   \item `stacomiR.printqueries`: a boolean, default FALSE, with the side effect of printing queries to the console
+}
+}
+
+\author{
+\strong{Maintainer}: Cedric Briand \email{cedric.briand00 at gmail.com}
+
+Authors:
+\itemize{
+  \item Marion Legrand \email{<tableau-salt-loire at logrami.fr>}
+  \item Beaulaton Laurent \email{<laurent.beaulaton at ofb.gouv.fr>}
+}
+
+}
+\keyword{internal}

Modified: pkg/stacomirtools/tests/testthat/test-00-connectiondb.R
===================================================================
--- pkg/stacomirtools/tests/testthat/test-00-connectiondb.R	2021-10-26 07:05:49 UTC (rev 573)
+++ pkg/stacomirtools/tests/testthat/test-00-connectiondb.R	2021-11-02 17:53:43 UTC (rev 574)
@@ -16,7 +16,7 @@
 
 test_that("Test that ConnectionDB returns error when dbname length >1 ", {
 			skip_on_cran()
-			object<-new("ConnectionDB")
+			object <- new("ConnectionDB")
 			object at dbname <- c("bd_contmig_nat","test")
 			object at host <- 		"localhost"
 			object at port <-		"5432"

Modified: pkg/stacomirtools/tests/testthat/test-02-requeteDB.R
===================================================================
--- pkg/stacomirtools/tests/testthat/test-02-requeteDB.R	2021-10-26 07:05:49 UTC (rev 573)
+++ pkg/stacomirtools/tests/testthat/test-02-requeteDB.R	2021-11-02 17:53:43 UTC (rev 574)
@@ -13,12 +13,59 @@
 			expect_gt(nrow(object at query),0)
 		})
 
+test_that("Test that RequeteDB works when passed arguments base", {
+			skip_on_cran()
+			object <-new("RequeteDB")
+			base <-
+					c("bd_contmig_nat", "localhost", "5432", "postgres", "postgres")
+			object at sql <- "select * from iav.t_lot_lot limit 10"
+			object <- query(object, base)
+			expect_that(object at connection,is_a("Pool"))
+			expect_gt(nrow(object at query),0)
+		})
 
-test_that("Test that RequeteDB returns the sql string when envir_stacomi and showmerequest ", {
+test_that("Test that RequeteDB works when using options", {
 			skip_on_cran()
-			skip_if_not_installed ("stacomiR")
-			envir_stacomi <- new.env(parent=asNamespace("stacomiR"))
-			assign("showmerequest",1,envir_stacomi)
+			o <- options()
+			options(					
+							stacomiR.dbname = "bd_contmig_nat",
+							stacomiR.host ="localhost",
+							stacomiR.port = "5432",
+							stacomiR.user = "postgres",
+							stacomiR.password = "postgres"					
+					)	
+			object <-new("RequeteDB")
+			object at sql <- "select * from iav.t_lot_lot limit 10"
+			object <- query(object)
+
+			expect_that(object at connection,is_a("Pool"))
+			expect_gt(nrow(object at query),0)
+			options(o)
+		})
+
+
+test_that("Test that RequeteDB does not work when using wrong options and no base", {
+			skip_on_cran()
+			o <- options()
+			options(					
+					stacomiR.dbname = "bd_contmig_nat",
+					stacomiR.host ="localhost",
+					stacomiR.port = "5432",
+					stacomiR.user = "",
+					stacomiR.password = ""					
+			)	
+			object <-new("RequeteDB")
+			object at sql <- "select * from iav.t_lot_lot limit 10"
+			expect_error(object <- query(object))
+			options(o)
+		})
+
+
+test_that("Test that RequeteDB returns the sql string when options(stacomiR.printquery=TRUE) ", {
+			skip_on_cran()
+			options(					
+					stacomiR.printqueries = TRUE
+			)	
 			object <- new("RequeteDB")
 			object at sql <- "select * from iav.t_lot_lot limit 10"
 			object at dbname <- "bd_contmig_nat"
@@ -26,7 +73,6 @@
 			object at port <-		"5432"
 			object at user <-		"postgres"
 			object at password <-		"postgres" 
-			#object at silent <- FALSE
 			expect_output(object<-query(object))
 			
 			



More information about the Stacomir-commits mailing list