Learn R Programming

r2lh (version 0.6.1)

rthu: ~ Function: R to HTML, Univariate analysis ~

Description

rthu performs some basic analyses, then generates code to be included in a HTML document.

Usage

rthu(x,fileOut="",textBefore="",textAfter="",graphDir="graphUniv",graphName="V",type="png",limDiscrete=10)

Arguments

x
[data.frame] or [vector] : contains the data to analyse.
fileOut
[character]; name of the output file in which the HTML summary will be saved. If empty, the HTML code is printed on screen.
textBefore
[character] or [vector(character)] : before printing a variable analysis, rthu can write a text. If rthu is applied on a single variable, textBefore should be of length 1. If rthu
textAfter
[character] or [vector(character)] : after printing a variable analysis, rthu can write a text. If rthu is applied on a single variable, textAfter should be of length 1. If rthu
graphDir
[character] : directory used to save the graphs generated by the analyses.
graphName
[character] or [vector(character)] : prefix for the graph names. If empty, the graph names are 'V1' to 'V'length(data.frame)
type
[character] : type of plotting device used to export the graphics. Can be Windows metafile, PNG, JPEG, BMP (Windows bitmap format), TIFF, PostScript or PDF.
limDiscrete
rthu distinguishes two kinds of numeric : discrete designates numeric variables with only a few modalities, continuous designates numeric variables with many mod

Value

  • rthu generates HTML code and either prints it on the screen, or saves it in a file. It also generates several graphs, optionally in a different directory.

Classical usage

The use of rthu goes through the following steps: ll{ Step 1. Load the data (usually, a data.frame). Step 2. Optionally, set some variables as ordered. Step 3. Run rthu(dataFrame,"fileOut.html"). } See examples of application.

Author

Christophe Genolini christophe.genolini@free.fr PSIGIAM: Paris Sud Innovation Group in Adolescent Mental Health INSERM U669 / Maison de Solenn / Paris Bernard Desgraupes bernard.desgraupes@u-paris10.fr University of Paris Ouest - Nanterre

English correction

Jean-Marc Chamot jchamot@u-paris10.fr Laboratoire "Sport & Culture" / "Sports & Culture" Laboratory University of Paris Ouest - Nanterre

Details

rthu performs some basic analyses, then generates code to be included in a HTML document. rthu performs the analyses automatically according to the data class. It considers 4 classes. The analysis of the variable depends on the class:
  1. factor, character and logical: Frequency ; Graph: barplot
  2. ordered: Frequency, quartile ; Graph: barplot
  3. numeric discrete: Frequency, mean, variance, quartile ; Graph: boxplot and barplot
  4. numeric continuous: Mean, variance, quartile ; Graph: boxplot and histogram.
On a data.frame, rthu runs the analyses on every column.

References

HTML web site http://www.w3.org/TR/html/ Data are available on line: http://christophe.genolini.free.fr/EPO/EPO2007-Fraude.php

See Also

rthMainFile, rthb, r2lUniv-package, examCheating

Examples

Run this code
# # # # # # # # # # # # # # # # # # #
#   R to HTML,  Univariate Analyses   #
 #             Examples              #
  #       rthu single variable      #
   # # # # # # # # # # # # # # # # #

########################

### Create some data
par(ask=FALSE)
V1 <- factor(LETTERS[floor(runif(50,1,4))])
V2 <- rnorm(50,1,1)<0
V3 <- ordered(LETTERS[floor(runif(50,1,4))])

### Create a directory for the output
r2lhOutDir <- paste(tempdir(),"rthuExample",sep="/")
if(!file.exists(r2lhOutDir)){dir.create(r2lhOutDir)}
setwd(r2lhOutDir)

### Execute rthu
rthu(V1,fileOut="first.html",textBefore="<h2>Variable 1 to 3</h2>",graphName="V1")
rthu(V2,fileOut="second.html",graphName="V2")
rthu(V3,fileOut="third.html",textBefore="This is variable 3",graphDir="P")
rthMainFile(text="<LU>
<LI><A HREF='first.html'>First example</A></LI>
<LI><A HREF='second.html'>Second example</A></LI>
<LI><A HREF='third.html'>Third example</A></LI>
</LU>
")


 # # # # # # # # # # # # # # # # # # #
#   R to HTML,  Univariate Analyses   #
 #          Real examples            #
  #        rthu data.frame          #
   # # # # # # # # # # # # # # # # #

########################
###### Step 1: Create the data

data(examCheating)
str(examCheating)

########################
###### Step 2: ordering variable

examCheating$YearOfStudy <- ordered(examCheating$YearOfStudy,levels=c("L1","L2","L3","M1","M2"))
examCheating$Bac <- ordered(examCheating$Bac,levels=c("Remedial exam","Pass","Fairly good","Good","Very good","Summa cum laude"))
for(iColumn in 8:17){
    examCheating[,iColumn] <- ordered(examCheating[,iColumn],levels=c("Never","Rarely","Sometimes","Often","Always"))
}
str(examCheating)


########################
###### Step 3: running r2hu

### The following code will create some files.
### So we first move to a directory.
r2lhOutDir <- paste(tempdir(),"rthuReal",sep="/")
if(!file.exists(r2lhOutDir)){dir.create(r2lhOutDir)}
setwd(r2lhOutDir)


### Then we prepare the textBefore, for transition between variable
textBefore <- paste("<h3>",names(examCheating)[c(2:5,18:20)],"</h3>",sep="")

text <- "<h2>Survey</h2>
  <ul>
    <li> What is your age?</li>
    <li> What is your gender?<li>
    <li> What is your level?<li>
    <li> What is your field?<li>
    <li> Did you cheat at Bac?<li>
    <li> Did you cheat high scool?<li>
    <li> Cheating score<li>
  </ul>

<h2>Univariate analysis</h2>
  <OBJECT data = 'ExamCheat-univ.html' type = 'text/html'></OBJECT>


<h2>More information?</h2>
For a detailled analysis, see
http://christophe.genolini.free.fr/EPO/2007 Fraude/EPO2007-Fraude-Rapport.pdf"

### We can run r2hu
rthu(examCheating[,c(2:5,18:20)],fileOut="ExamCheat-univ.html",textBefore=textBefore)
rthMainFile("ExamCheat-main.html",text=text)
setwd("../..")

Run the code above in your browser using DataLab