[Stacomir-commits] r416 - in pkg/stacomirtools: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Jun 24 20:33:05 CEST 2017
Author: briand
Date: 2017-06-24 20:33:04 +0200 (Sat, 24 Jun 2017)
New Revision: 416
Modified:
pkg/stacomirtools/DESCRIPTION
pkg/stacomirtools/R/ConnectionODBC.r
pkg/stacomirtools/R/RequeteODBC.r
pkg/stacomirtools/R/utilities.r
pkg/stacomirtools/man/chnames.Rd
pkg/stacomirtools/man/connect-methods.Rd
pkg/stacomirtools/man/induk.Rd
pkg/stacomirtools/man/is.even.Rd
pkg/stacomirtools/man/is.odd.Rd
pkg/stacomirtools/man/killfactor.Rd
pkg/stacomirtools/man/tab2df.Rd
Log:
Providing examples for some functions (as requested by Uwe ligges from CRAN)
Modified: pkg/stacomirtools/DESCRIPTION
===================================================================
--- pkg/stacomirtools/DESCRIPTION 2017-06-22 18:44:14 UTC (rev 415)
+++ pkg/stacomirtools/DESCRIPTION 2017-06-24 18:33:04 UTC (rev 416)
@@ -5,8 +5,8 @@
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 the ODBC connection, also provides some
- utilities to paste small datasets to clipboard, rename columns. It is used by the package stacomiR for
+Description:S4 class wrappers for the 'ODBC' 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.
License: GPL (>= 2)
Collate:
Modified: pkg/stacomirtools/R/ConnectionODBC.r
===================================================================
--- pkg/stacomirtools/R/ConnectionODBC.r 2017-06-22 18:44:14 UTC (rev 415)
+++ pkg/stacomirtools/R/ConnectionODBC.r 2017-06-24 18:33:04 UTC (rev 416)
@@ -19,21 +19,29 @@
#' @slot query="data.frame"
#' @return connectionODBC an S4 object of class connectionODBC
#' @examples
+#' ##this wont be run as the user need to manually configure the connection before using it
+#' \dontrun{
#' object=new("ConnectionODBC")
#' object at baseODBC=c("myODBCconnection","myusername","mypassword")
#' object at silent=FALSE
#' object<-connect(object)
#' odbcClose(object at connection)
+#' }
setClass(Class="ConnectionODBC",
representation= representation(baseODBC="vector",silent="logical",etat="ANY",connection="ANY"),
prototype = list(silent=TRUE),
validity=validity_ODBC)
+
+#' generic connect function for baseODBC
+#' @export
setGeneric("connect",def=function(object,...) standardGeneric("connect"))
#' connect method for ConnectionODBC class
#' @return a connection with slot filled
#' @author Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
-#' @examples object=new("ConnectionODBC")
+#' @examples
+#' object=new("ConnectionODBC")
+#'
#' object at baseODBC=baseODBC
#' connect(object)
setMethod("connect",signature=signature("ConnectionODBC"),definition=function(object) {
Modified: pkg/stacomirtools/R/RequeteODBC.r
===================================================================
--- pkg/stacomirtools/R/RequeteODBC.r 2017-06-22 18:44:14 UTC (rev 415)
+++ pkg/stacomirtools/R/RequeteODBC.r 2017-06-24 18:33:04 UTC (rev 416)
@@ -59,10 +59,42 @@
msg6<-gettext("success")
verbose<-exists("showmerequest",envir=envir_stacomi)
+
+
+#' Function loaded in this package to avoid errors, if the package is called
+#' without stacomiR
+#'
+#' This function will be replaced by a longer function using gWidgets if the
+#' package stacomiR is loaded. It is provided there to avoid to pointing to an
+#' undefined global function. Normally the program tests for the existence of
+#' and environment envir_stacomi which indicates that the messages are to be
+#' displayed in the gWidget interface, so this code is to avoid notes in
+#' R.check.
+#'
+#'
+#' @param text The text to display
+#' @param arret If true calls the program to stop and the message to be
+#' displayed
+#' @param wash 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}
funout<-function(text,arret=FALSE){
if(arret) stop(text) else print(text)
return(NULL)
}
+
+
+#' very usefull function remove factor that appear, noticeably after loading
+#' with ODBC
+#'
+#' function used to remove factors that appear, noticeably after loading with
+#' ODBC
+#'
+#'
+#' @param df a data.frame
+#' @return df
+#' @author Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
+#' @export killfactor
killfactor=function(df){
for (i in 1:ncol(df))
{
@@ -123,4 +155,4 @@
}
return(object)
- })
\ No newline at end of file
+ })
Modified: pkg/stacomirtools/R/utilities.r
===================================================================
--- pkg/stacomirtools/R/utilities.r 2017-06-22 18:44:14 UTC (rev 415)
+++ pkg/stacomirtools/R/utilities.r 2017-06-24 18:33:04 UTC (rev 416)
@@ -5,16 +5,25 @@
#############################################
# functions copied from Hmisc
#############################################
+
+
#' function used to print the html tables of output (see xtable documentation)
+#'
+#' see \pkg{xtable} for further description, an xtable is created and printed
+#' to html format
+#'
+#'
#' @param data a data frame
#' @param caption the caption
-#' @param top of top the caption is placed on top
-#' @param outfile outfile is the path to the file
+#' @param top a logical, if true the caption is placed on top
+#' @param outfile the path to the file
#' @param clipboard if clipboard TRUE, a copy to the clipboard is made
#' @param append is the file appended to the previous one ?
-#' @param digits
-#' @param ...
+#' @param digits the number of digits
+#' @param ... additional parameters to be passed to the function
+#' @return an xtable
#' @author Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
+#' @export funhtml
funhtml=function(data,caption=NULL,top=TRUE,outfile=NULL,clipboard=FALSE,append=TRUE,digits=NULL,...){
xt=xtable::xtable(data, caption=caption,digits=digits)
@@ -25,13 +34,19 @@
###########################################
# special functions (exported as they are usefull)
#############################################
+
+
#' This function replaces the variable names in a data.frame
+#'
+#' This function replaces the variable names in a data.frame
+#'
+#'
#' @param object a data frame
-#' @param old_variable_name
-#' @param new_variable_name
+#' @param old_variable_name a character vector with old variables names
+#' @param new_variable_name a character vector with new variables names
#' @return object
#' @author Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
-#' @export
+#' @export chnames
chnames=function(object,
old_variable_name,
new_variable_name){
@@ -43,14 +58,20 @@
return(object)
}
-# fonction qui retourne l'index des valeurs repetees d'un vecteur
-# see duplicated
-#' fonction qui renvoit l'index des valeurs apparaissant une seule fois
-#' @param a
-#' @return the index unique values within a vector
+
+
+#' unique values of a vector
+#'
+#' returns the index of values appearing only once in a vector :
+#' match(unique(a),a), replicated values are not returned on their second
+#' occurence
+#'
+#'
+#' @param a a vector
+#' @return the index unique values within a vector
#' @author Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
-#' @export
+#' @export induk
induk=function(a){
sol=match(unique(a),a) #index des valeurs uniques
return(sol)
@@ -71,10 +92,16 @@
return(df)
}
-#' ex fonction to write to excel, not used within the program but can still be used
-#' @param d
+
+
+#' ex fonction to write to the clipboard
+#'
+#' ex fonction to write to the clipboard
+#'
+#'
+#' @param d a dataframe
#' @author Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
-#' @export
+#' @export ex
ex<-function(d=NULL){
if (is.null(d)){
xl=utils::select.list(choices=ls(envir=globalenv()), preselect = NULL, multiple = FALSE, title = "choisir l'object")
@@ -86,11 +113,18 @@
-#' id.odd function modified from package sma (which did not verify that the entry was indeed an integer)
-#' @param x
+
+
+#' id.odd function modified from package sma
+#'
+#' id.odd function modified from package sma (which did not verify that the
+#' entry was indeed an integer)
+#'
+#'
+#' @param x integer
#' @return a logical
-#' @author Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
-#' @export
+#' @author Adapted from Henrik Bengtsson
+#' @export is.odd
is.odd=function (x)
{
if (x==as.integer(x)) {
@@ -105,11 +139,18 @@
stop("is.odd should be used with an integer")
}
}
-#' is.even function modified from package sma (which did not verified that the entry was indeed an integer)
-#' @param x
+
+
+#' is.even function modified from package sma
+#'
+#' is.even function modified from package sma (which did not verify that the
+#' entry was indeed an integer)
+#'
+#'
+#' @param x integer
#' @return a logical
-#' @author Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
-#' @export
+#' @author Adapted from Henrik Bengtsson
+#' @export is.even
is.even=function (x)
{
if (x==as.integer(x)) {
@@ -125,10 +166,18 @@
}
}
-#' Function to transform a ftable into dataframe but just keeping the counts works with ftable of dim 2
-#' @param tab
+
+
+#' Function to transform a ftable into dataframe but just keeping the counts,
+#' works with ftable of dim 2
+#'
+#' Function to transform a ftable into dataframe but just keeping the counts
+#' works with ftable of dim 2
+#'
+#'
+#' @param tab a flat table
#' @author Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
-#' @export
+#' @export tab2df
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)))
@@ -145,4 +194,4 @@
#' @export
funout<-function(text,arret=FALSE,wash=FALSE){
if(arret) stop(text) else print(text,quote=FALSE)
-}
\ No newline at end of file
+}
Modified: pkg/stacomirtools/man/chnames.Rd
===================================================================
--- pkg/stacomirtools/man/chnames.Rd 2017-06-22 18:44:14 UTC (rev 415)
+++ pkg/stacomirtools/man/chnames.Rd 2017-06-24 18:33:04 UTC (rev 416)
@@ -20,4 +20,16 @@
\author{
Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
}
+\examples{
+df <- data.frame("var1" = c("blue","red"), "var2" = c("nice","ugly"))
+colnames(df) # "var1" "var2"
+df <- chnames(object = df, old_variable_name = c("var1","var2"),
+"new_variable_name" = c("color","beauty"))
+colnames(df) # "color" "beauty"
+# the following will return an error, as the variable wrong_name is not in variable names
+\dontrun{
+chnames(object = df, old_variable_name = c("wrong_name"),
+"new_variable_name" = c("color")))
+}
+}
Modified: pkg/stacomirtools/man/connect-methods.Rd
===================================================================
--- pkg/stacomirtools/man/connect-methods.Rd 2017-06-22 18:44:14 UTC (rev 415)
+++ pkg/stacomirtools/man/connect-methods.Rd 2017-06-24 18:33:04 UTC (rev 416)
@@ -22,8 +22,9 @@
\keyword{methods}
\examples{
showMethods("connect")
-##
-#object<-new("RequeteODBCwhere")
-#connect(object)
+\dontrun{
+object<-new("RequeteODBCwhere")
+connect(object)
}
+}
Modified: pkg/stacomirtools/man/induk.Rd
===================================================================
--- pkg/stacomirtools/man/induk.Rd 2017-06-22 18:44:14 UTC (rev 415)
+++ pkg/stacomirtools/man/induk.Rd 2017-06-24 18:33:04 UTC (rev 416)
@@ -16,4 +16,6 @@
\author{
Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
}
-
+\examples{
+induk(c(1,1,2,2,2,3))
+}
Modified: pkg/stacomirtools/man/is.even.Rd
===================================================================
--- pkg/stacomirtools/man/is.even.Rd 2017-06-22 18:44:14 UTC (rev 415)
+++ pkg/stacomirtools/man/is.even.Rd 2017-06-24 18:33:04 UTC (rev 416)
@@ -18,4 +18,8 @@
Adapted from Henrik Bengtsson
}
+\examples{
+is.even(1)
+is.even(2)
+}
Modified: pkg/stacomirtools/man/is.odd.Rd
===================================================================
--- pkg/stacomirtools/man/is.odd.Rd 2017-06-22 18:44:14 UTC (rev 415)
+++ pkg/stacomirtools/man/is.odd.Rd 2017-06-24 18:33:04 UTC (rev 416)
@@ -17,4 +17,7 @@
\author{
Adapted from Henrik Bengtsson
}
-
+\examples{
+is.odd(1)
+is.odd(2)
+}
Modified: pkg/stacomirtools/man/killfactor.Rd
===================================================================
--- pkg/stacomirtools/man/killfactor.Rd 2017-06-22 18:44:14 UTC (rev 415)
+++ pkg/stacomirtools/man/killfactor.Rd 2017-06-24 18:33:04 UTC (rev 416)
@@ -16,4 +16,10 @@
\author{
Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
}
-
+\examples{
+df <- data.frame("var1" = c("blue","red"),"var2"=c("nice","ugly"))
+df[,"var1"] <- as.factor(df[,"var1"])
+df[,"var2"] <- as.factor(df[,"var2"])
+df <- killfactor(df)
+apply(df,1,function(x) is.factor(x)) # FALSE FALSE
+}
Modified: pkg/stacomirtools/man/tab2df.Rd
===================================================================
--- pkg/stacomirtools/man/tab2df.Rd 2017-06-22 18:44:14 UTC (rev 415)
+++ pkg/stacomirtools/man/tab2df.Rd 2017-06-24 18:33:04 UTC (rev 416)
@@ -14,4 +14,8 @@
\author{
Cedric Briand \email{cedric.briand"at"eptb-vilaine.fr}
}
-
+\examples{
+df <- data.frame("var1" = c("blue","red"), "var2" = c("nice","ugly"))
+ftdf <- ftable(df)
+tab2df(ftdf)
+}
More information about the Stacomir-commits
mailing list