Skip to content

Commit

Permalink
- Add a html.new() function (convenience method that does html.clear(…
Browse files Browse the repository at this point in the history
…) followed by html.add())

- fix broken tests
  • Loading branch information
perNyfelt committed Jan 14, 2021
1 parent 554a1a2 commit 532d9ee
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
export(Html)
export(html.add)
export(html.clear)
export(html.new)
export(as.character.Html)
export(html.table)
export(html.imgPlot)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ html creating methods directly. The underlying html creating methods are:
# Version history

## 1.4
- Add a html.new() function (convenience method that does html.clear() followed by html.add())
- fix broken tests

## 1.3
- use a dedicated env to avoid accidental overwrites
Expand Down
5 changes: 5 additions & 0 deletions src/main/R/Html.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ html.clear <- function() {
.htmlcreatorEnv$html <- Html$new()
}

html.new <- function(x, ...) {
html.clear()
html.add(x, ...)
}

setMethod('as.vector', signature("Html"),
function(x) {
x$getContent()
Expand Down
18 changes: 7 additions & 11 deletions src/test/R/HtmlcontentTest.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,16 @@ test.dataFrameToTable <- function() {
}

test.plotToImage <- function() {
html.clear()
html.add("<html><body>")
html.add(
html.new(
barplot,
table(mtcars$vs, mtcars$gear),
main="Car Distribution by Gears and VS",
col=c("darkblue","red")
)
html.add("</html></body>")
#outFile <- tempfile("plot", fileext = ".html")
#write(html$getContent(), outFile)
outFile <- paste0(getwd(), "test.plotToImage.html")
write(html.content(), outFile)
#print(paste("Wrote", outFile))
assertThat(nchar(html.content()), equalTo(5754))
assertThat(nchar(html.content()), equalTo(12356))
}

test.imgUrl <- function() {
Expand All @@ -67,14 +64,13 @@ test.imgUrl <- function() {

test.matrix <- function() {
html.clear()
html.add("<html><body>")
html.add("<h2>PlantGrowth weight</h2>")
html.add(
hist,
PlantGrowth$weight
)
html.add(format(summary(PlantGrowth)))

html.add("</body></html>")
assertThat(nchar(html.content()), equalTo(7059))
outFile <- paste0(getwd(), "test.matrix.html")
write(html.content(), outFile)
assertThat(nchar(html.content()), equalTo(12409))
}

0 comments on commit 532d9ee

Please sign in to comment.