Context
xml_reserved_chars_to_named_entities <- function(string) {
if(string == "" || identical(string, character(0))) return("")
if(length(string) > 1) sapply(string, xml_reserved_chars_to_named_entities)
chars <- unlist(strsplit(string, ""))
pattern <- c('<', '&', '>', "'", '"')
replacement <- c('<', '&', '>', ''', '"')
result = chars
for (i in seq_along(pattern)) {
result[grep(pattern[i], chars)] = replacement[i]
}
paste0(result)
}
Problem
The function above, returns TRUE
on identical(xml_reserved_chars_to_named_entities("''"), "''")
but fails to pass the following test (using testthat
package) with:
test_that("xml_reserved_chars_to_named_entities",
{
expect_identical(xml_reserved_chars_to_named_entities("''"), "''")
}
)
I was expecting it to pass that test as it gives TRUE
with identical
's call. Why is not that so?
Here is testthat
feedback on that test:
Failed -------------------------------------------------------------------------
1. Failure: xml_reserved_chars_to_named_entities (@test-utils.R#48) ------------
xml_reserved_chars_to_named_entities("''") not identical to "''".
Lengths differ: 2 vs 1
Version details
My R version is 3.3.0
and that of testthat
is 1.0.2
. Help is appreciated.