I have already done this, so I know it's possible, and it might be a very simple issue, so I am sorry if the question is not good enough, but here is the deal:
I have a code in R to generate a few analysis from a stock: the log return, the histogram, a descriptive statistics from its value and the log returns, and so on.
What I want is to make a cool html with this results. I had something similar in my old job long time ago, but I am really struggling to remember exactly how I put the results into the html.
It starts with an empty object, then I add html codes and within the codes I start to insert my results. After that I use write.table and my work is done. Not sure why it is not working this time. I thought it could be something from the number of rows and columns some results have, but I couldn't solve the issue. This is what will generate the html:
HTMLGenerator<- ""
HTMLGenerator[length(HTMLGenerator)+1]<-paste("<!DOCTYPE html>",sep="")
HTMLGenerator[length(HTMLGenerator)+1]<-paste("<html>",sep="")
HTMLGenerator[length(HTMLGenerator)+1]<-paste("<head>",sep="")
HTMLGenerator[length(HTMLGenerator)+1]<-paste("<title>Stock Analysis</title>",sep="")
HTMLGenerator[length(HTMLGenerator)+1]<-paste("</head>",sep="")
HTMLGenerator[length(HTMLGenerator)+1]<-paste("<body>",sep="")
HTMLGenerator[length(HTMLGenerator)+1]<-paste("<h2>Stock Analysis</h2>",sep="")
HTMLGenerator[length(HTMLGenerator)+1]<-paste("<h3>Stock: CSAN3</h3>",sep="")
HTMLGenerator[length(HTMLGenerator)+1]<-paste("<h3>Made by me</h3>",sep="")
HTMLGenerator[length(HTMLGenerator)+1]<-paste("The Log Returns from CSAN3 are:\"",LogReturnCsan,"\" ",sep="" )
HTMLGenerator[length(HTMLGenerator)+1]<-paste(" \"",DescriptiveStat,"\" ",sep="" )
HTMLGenerator[length(HTMLGenerator)+1]<-paste(" \"",Histogram ,"\" ",sep="" )
HTMLGenerator[length(HTMLGenerator)+1]<-paste("</body>",sep="")
write.table(HTMLGenerator,"C:/Users/Desktop/FinalAnalysis.html",sep="\t", quote=FALSE, row.names=FALSE, col.names=FALSE)
And this is what the R code looks like:
#Read the stock information
Csan <- read.table("C:/Users/Desktop/csan.txt",header = TRUE, sep = ",", dec = ".", fill = TRUE)
#get the stock log return based on the close value from each day
LogReturnCsan <- diff(log(Csan$Close))
DescriptiveStat <- summary(LogReturnCsan)
#Makes a histogram with the log returbs
Histogram <- hist(LogReturnCsan, breaks=30, col="burlywood3", main="LN Return Csan3 ")
The HTML is failing to get the results from R such as the LogReturnCsan, DescriptiveStat and Histogram.
This is the content of csan.txt, each column is separated by "," and the decimals by "." (It is the Year, Day, Month, DayMonth, Open Value, Highest Value of the stock in the day, Lowest Value of the stock in the day, Close price in the day, Volume of tradings, Close Value adjusted):
Ano,Dia,Mes,DiaMes,Open,High,Low,Close,Volume,AdjClose
2010,04,01,04 - 01,22.6185,22.7429,21.9964,22.6629,1088200,20.10939
2010,05,01,05 - 01,22.7696,23.0006,22.103,22.6718,2295300,20.11728
2010,06,01,06 - 01,22.503,22.7518,21.8364,22.023,2115500,19.54159
2010,07,01,07 - 01,21.7297,21.8186,20.3078,20.8499,8368700,18.50066