Skip to content

Commit 8f137d8

Browse files
committed
Return invisibly from write_xml
When we switched to `.Call` it inadvertently now returns `NULL` visibly, instead of invisibly. Fixes #307
1 parent 9928883 commit 8f137d8

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# xml2 (development version)
22

3+
* `write_xml()` and `write_html()` now return NULL invisibly, as they did prior to version 1.3.0 (#307)
4+
35
# xml2 1.3.2
46

57
* `read_html()` and `read_xml()` now error if passed strings of length greater than one (#121)

R/xml_write.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ write_xml.xml_document <- function(x, file, ..., options = "format", encoding =
5151
}
5252
.Call(doc_write_file, x$doc, file, encoding, options)
5353
}
54+
55+
invisible()
5456
}
5557

5658
#' @export
@@ -74,6 +76,8 @@ write_xml.xml_nodeset <- function(x, file, ..., options = "format", encoding = "
7476
}
7577
.Call(node_write_file, x[[1]]$node, file, encoding, options)
7678
}
79+
80+
invisible()
7781
}
7882

7983
#' @export
@@ -93,6 +97,8 @@ write_xml.xml_node <- function(x, file, ..., options = "format", encoding = "UTF
9397
}
9498
.Call(node_write_file, x$node, file, encoding, options)
9599
}
100+
101+
invisible()
96102
}
97103

98104

tests/testthat/test-write_xml.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,14 @@ test_that("write_html work with html input", {
110110
expect_identical(readChar(file, 1000L),
111111
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<title>Foo</title>\n</head></html>\n")
112112
})
113+
114+
test_that("write_xml returns invisibly", {
115+
x <- read_xml("<x>foo</x>")
116+
tf <- tempfile()
117+
on.exit(unlink(tf))
118+
119+
res <- withVisible(write_xml(x, tf))
120+
121+
expect_equal(res$value, NULL)
122+
expect_equal(res$visible, FALSE)
123+
})

0 commit comments

Comments
 (0)