################################################################# # A recopier en fin du fichier Rcmdr-menus.txt, situé dans le # dossier "library/Rcmdr/etc" de l'installation R ################################################################# # ajout des fonctions associées au menu Rapports rapportConsole = function() { if (activeDataSet()==FALSE) { tkmessageBox(message="selectionnez un tableau de donnees actif, svp") stop("fin"); } tabActif = get(activeDataSet()) # Création de la boite de dialogue (nommée formu) formu = tktoplevel() tktitle(formu) = "Creation d'un rapport" # fonction associée au bouton OK executer = function() { # recuperation des valeurs variable = tclvalue( tkget(zone_variable,tkcurselection(zone_variable)) ) legende = as.character( tkget(zone_legende) ) # affichage du resume resume = summary(tabActif[[variable]]) print(resume) # graphique : boite à moustaches ou camembert if (is.numeric(tabActif[[variable]])) { boxplot(tabActif[[variable]], main=legende) } else { pie(table(tabActif[[variable]]), main=legende) } } # fonction associée au bouton quitter quitter = function() { tkdestroy(formu) } # creation des composants : label_variable, zone_variable, label_legende... label_variable = tklabel(formu, text="variable : ") zone_variable = tklistbox(formu, height=length(names(tabActif)), exportselection=0) for (element in names(tabActif)) { tkinsert(zone_variable,"end",element) } label_legende = tklabel(formu, text="legende : ") zone_legende = tkentry(formu) bouton_ok = tkbutton(formu, text="OK", command=executer) bouton_quitter = tkbutton(formu, text="Quitter", command=quitter) # positionnement des composants sur 3 lignes tkgrid(label_variable, zone_variable) tkgrid(label_legende, zone_legende) tkgrid(bouton_ok, bouton_quitter) # affichage de la fenetre tkfocus(formu) } rapportOdf = function() { require(odfWeave) # Création de la boite de dialogue (nommée formu) formu = tktoplevel() tktitle(formu) = "Transformation d'un rapport Writer" # fonction associée au bouton OK executer = function() { # recuperation des valeurs source = as.character( tkget(zone_source) ) destination = as.character( tkget(zone_destination) ) compression = tclvalue( tkget(zone_compression,tkcurselection(zone_compression)) ) # appel à odfWeave if(compression=="7z") { zip = '"c:/Program Files/7-Zip/7z.exe"' # vérifier l'installation du logiciel de compression 7z cmd = c( paste(zip,"a -tzip $$file$$ .") , paste(zip,"e -tzip $$file$$") ) odfWeave(source, destination, control=odfWeaveControl(zipCmd=cmd)) } else { phrase = paste("odfWeave('", source, "','", destination, "')", sep="") doItAndPrint(phrase) } } # fonction associée au bouton quitter quitter = function() { tkdestroy(formu) } # creation des composants label_source = tklabel(formu, text="source : ") zone_source = tkentry(formu) label_destination = tklabel(formu, text="destination : ") zone_destination = tkentry(formu) label_compression = tklabel(formu, text="compression : ") zone_compression = tklistbox(formu, height=2, exportselection=0) tkinsert(zone_compression,"end","standard") tkinsert(zone_compression,"end","7z") tkselection.set(zone_compression,0) # choix de standard par defaut bouton_ok = tkbutton(formu, text="OK", command=executer) bouton_quitter = tkbutton(formu, text="Quitter", command=quitter) # positionnement des composants sur 4 lignes tkgrid(label_source, zone_source) tkgrid(label_destination, zone_destination) tkgrid(label_compression, zone_compression) tkgrid(bouton_ok, bouton_quitter) # affichage de la fenetre tkfocus(formu) } rapportHtml = function() { logger( "# squelette de programme R pour creer un rapport html" ) logger( "library(R2HTML)" ) logger( "HTMLInitFile(outdir=getwd(), filename='exemple', useLaTeX=FALSE, useGrid=FALSE)" ) logger( "HTML.title('Exemple de rapport', HR=1)" ) if (activeDataSet()!=FALSE) { logger( "HTML.title('Etude de la variable 1', HR=2)" ) # resume logger( "HTML.title('Resume', HR=3)" ) phrase = paste("HTML(summary(", activeDataSet(), "[[1]]", "))", sep="") logger( phrase ) # un graphique : boite à moustaches ou camembert logger( "HTML.title('Graphique', HR=3)" ) logger( "png('graphe.PNG')" ) if (is.numeric( get(activeDataSet())[[1]] )) { phrase = paste("boxplot(", activeDataSet(), "[[1]]", ")", sep="") } else { phrase = paste("pie(table(", activeDataSet(), "[[1]]", "))", sep="") } logger(phrase) logger("dev.off()") logger( "HTMLInsertGraph('graphe.PNG')" ) } logger( "# a compléter ...") logger( "HTMLEndFile()" ) }