[Rd] bug in utils:::format.person
Ivan Krylov
kry|ov@r00t @end|ng |rom gm@||@com
Fri Jun 2 19:58:54 CEST 2023
On Fri, 2 Jun 2023 16:55:59 +0200
Thierry Onkelinx via R-devel <r-devel using r-project.org> wrote:
> I think I found a bug in utils::format.person when using style = "R"
> with a vector of comments. The comment section is not parsed
> properly.
Good catch! This looks like another occasion of deparse() suddenly
returning a multi-element character vector where the caller expects a
single string:
format(person(c('J.', 'Random'), 'Hacker', comment = c(ORCID =
'0000-0000-0000-0000', foo = 'bar bar bar bar bar')), style = 'R')
# [1] "person(given = c(\"J.\", \"Random\"),"
# [2] " family = \"Hacker\","
# [3] " comment = c(ORCID = \"0000-0000-0000-0000\", foo = \"bar
# bar bar bar bar\"))"
format(person(c('J.', 'Random'), 'Hacker', comment = c(ORCID =
'0000-0000-0000-0000', foo = 'bar bar bar bar bar bar')), style = 'R')
# [1] "person(given = c(\"J.\", \"Random\"),"
# [2] " family = \"Hacker\","
# [3] " comment = c(\"c(ORCID = \\\"0000-0000-0000-0000\\\", foo =
# \\\"bar bar bar bar bar bar\\\"\", \")\"))"
The following seems to fix it:
--- src/library/utils/R/citation.R (revision 84486)
+++ src/library/utils/R/citation.R (working copy)
@@ -1014,7 +1014,7 @@
function(e) {
e <- e[!vapply(e, is.null, NA)]
cargs <-
- sprintf("%s = %s", names(e), sapply(e, deparse))
+ sprintf("%s = %s", names(e), sapply(e, deparse1))
.format_call_RR("person", cargs)
})
if(length(s) > 1L)
A regression test could be along the lines of:
p <- person(
'foo', 'bar', comment = c(
comment = 'just enough to deparse into multiple lines',
needs = 'multiple entries'
)
)
stopifnot(all.equal(
eval(parse(text = format(p, style = 'R')))$comment,
p$comment
))
--
Best regards,
Ivan
More information about the R-devel
mailing list