### Create some data
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(),"rtluExample",sep="/")
if(!file.exists(r2lhOutDir)){dir.create(r2lhOutDir)}
setwd(r2lhOutDir)
### Execute rtlu
rtlu(V1,fileOut="first.tex",textBefore="\\section{Variable 1 to 3}",graphName="V1")
rtlu(V2,fileOut="second.tex",graphName="V2")
rtlu(V3,fileOut="third.tex",textBefore="This is variable 3",graphDir="P")
rtlMainFile(text="\\input{first.tex}
\\input{second.tex}
\\input{third.tex}")
# # # # # # # # # # # # # # # # # # #
# R to LaTeX, Univariate Analyses #
# Real examples #
# rtlu 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 rtlu
### The following code will create some files.
### So we first move to a directory.
r2lhOutDir <- paste(tempdir(),"rtluReal",sep="/")
if(!file.exists(r2lhOutDir)){dir.create(r2lhOutDir)}
setwd(r2lhOutDir)
### Then we prepare the textBefore, for transition between variables
textBefore <- paste("\\subsection{",names(examCheating)[c(2:5,18:20)],"}",sep="")
text <- "\\maketitle
\\tableofcontents
\\section{Survey}
\\begin{enumerate}
\\item What is your age?
\\item What is your gender?
\\item What is your level?
\\item What is your field?
\\item Did you cheat at Bac?
\\item Did you cheat high scool?
\\item Cheating score
\\end{enumerate}
\\section{Univariate analysis}
\\input{ExamCheat-univ.tex}
\\section{More information?}
For a detailled analysis, see
http://christophe.genolini.free.fr/EPO/2007 Fraude/EPO2007-Fraude-Rapport.pdf"
### We can run r2lu
rtlu(examCheating[,c(2:5,18:20)],fileOut="ExamCheat-univ.tex",textBefore=textBefore)
rtlMainFile("ExamCheat-main.tex",text=text)
setwd("../..")
### Then compile main.tex twice. It is ready !
Run the code above in your browser using DataLab