Jump to content

CSV to HTML translation: Difference between revisions

Shared a Simple R implementation
(Shared a Simple R implementation)
Line 4,501:
[[File:Csv2html.PNG|500px|thumb|none]]
 
=={{header|R}}==
 
Using base R functions only, this is a very basic implementation and produces a simple HTML table
<lang R>File <- "~/test.csv"
Opened <- readLines(con = File)
Size <- length(Opened)
 
HTML <- "~/test.html"
 
Table <- list()
 
for(i in 1:Size)
{
#i=1
Split <- unlist(strsplit(Opened[i],split = ","))
Table[i] <- paste0("<td>",Split,"</td>",collapse = "")
Table[i] <- paste0("<tr>",Table[i],"</tr>")
}
 
Table[1] <- paste0("<table>",Table[1])
Table[length(Table)] <- paste0(Table[length(Table)],"</table>")
 
writeLines(as.character(Table), HTML)</lang>
 
'''Sample HTML output:'''
<lang html5><table><tr><td>Character</td><td>Speech</td></tr>
<tr><td>The multitude</td><td>The messiah! Show us the messiah!</td></tr>
<tr><td>Brians mother</td><td><angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry></td></tr>
<tr><td>The multitude</td><td>Who are you?</td></tr>
<tr><td>Brians mother</td><td>I'm his mother; that's who!</td></tr>
<tr><td>The multitude</td><td>Behold his mother! Behold his mother!</td></tr></table></lang>
=={{header|Racket}}==
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.