Dear all, 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. Please find below the mwe and the session info. Best regards, Thierry maintainer <- person( given = "Thierry", family = "Onkelinx", role = c("aut", "cre"), email = "thierry.onkelinx at inbo.be", comment = c( ORCID = "0000-0001-8804-4216", affiliation = "Research Institute for Nature and Forest (INBO)" ) ) format(maintainer, style = "R") |> cat(sep = "\n") # output person(given = "Thierry", family = "Onkelinx", role = c("aut", "cre"), email = "thierry.onkelinx at inbo.be", comment = c("c(ORCID = \"0000-0001-8804-4216\", affiliation \"Research Institute for Nature and Forest (INBO)\"", ")")) ? Session info ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? setting value version R version 4.3.0 (2023-04-21) os Ubuntu 22.04.2 LTS system x86_64, linux-gnu ui X11 language nl_BE:nl collate nl_BE.UTF-8 ctype nl_BE.UTF-8 tz Europe/Brussels date 2023-06-02 pandoc NA ? Packages ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? package * version date (UTC) lib source cli 3.6.1 2023-03-23 [1] CRAN (R 4.3.0) fortunes 1.5-4 2016-12-29 [1] CRAN (R 4.3.0) sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.3.0) ir. Thierry Onkelinx Statisticus / Statistician Vlaamse Overheid / Government of Flanders INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND FOREST Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance thierry.onkelinx at inbo.be Havenlaan 88 bus 73, 1000 Brussel www.inbo.be /////////////////////////////////////////////////////////////////////////////////////////// To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey /////////////////////////////////////////////////////////////////////////////////////////// <https://www.inbo.be> [[alternative HTML version deleted]]
On Fri, 2 Jun 2023 16:55:59 +0200 Thierry Onkelinx via R-devel <r-devel at 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
Thierry, thanks for this, this is a bug in utils:::.format_person_as_R_code(). This calls deparse() on the elements of the person object with the default width.cutoff = 60. As your comment exceeds this width, the erroneous formatting is produced. The simplest reproducible example I could come up with was: p <- person(".", comment = c(foo = ".....................", bar = ".....................")) writeLines(format(p, style = "R")) This can be fixed in line 1017 of utils/R/citation.R either by increasing the width.cutoff, e.g., sprintf("%s = %s", names(e), sapply(e, deparse, width.cutoff = 500L)) but, of course, this still has an arbitrary cutoff. So maybe better sprintf("%s = %s", names(e), sapply(e, function(x) paste(deparse(x), collapse = ""))) which should work. I'll ping Kurt about this and try to coordinate a fix. Best wishes, Achim On Fri, 2 Jun 2023, Thierry Onkelinx via R-devel wrote:> Dear all, > > 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. Please find > below the mwe and the session info. > > Best regards, > > Thierry > > maintainer <- person( > given = "Thierry", family = "Onkelinx", role = c("aut", "cre"), > email = "thierry.onkelinx at inbo.be", > comment = c( > ORCID = "0000-0001-8804-4216", > affiliation = "Research Institute for Nature and Forest (INBO)" > ) > ) > format(maintainer, style = "R") |> > cat(sep = "\n") > # output > person(given = "Thierry", > family = "Onkelinx", > role = c("aut", "cre"), > email = "thierry.onkelinx at inbo.be", > comment = c("c(ORCID = \"0000-0001-8804-4216\", affiliation > \"Research Institute for Nature and Forest (INBO)\"", ")")) > > ? Session info > ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? > setting value > version R version 4.3.0 (2023-04-21) > os Ubuntu 22.04.2 LTS > system x86_64, linux-gnu > ui X11 > language nl_BE:nl > collate nl_BE.UTF-8 > ctype nl_BE.UTF-8 > tz Europe/Brussels > date 2023-06-02 > pandoc NA > > ? Packages > ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? > package * version date (UTC) lib source > cli 3.6.1 2023-03-23 [1] CRAN (R 4.3.0) > fortunes 1.5-4 2016-12-29 [1] CRAN (R 4.3.0) > sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.3.0) > > > > ir. Thierry Onkelinx > Statisticus / Statistician > > Vlaamse Overheid / Government of Flanders > INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND > FOREST > Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance > thierry.onkelinx at inbo.be > Havenlaan 88 bus 73, 1000 Brussel > www.inbo.be > > /////////////////////////////////////////////////////////////////////////////////////////// > To call in the statistician after the experiment is done may be no more > than asking him to perform a post-mortem examination: he may be able to say > what the experiment died of. ~ Sir Ronald Aylmer Fisher > The plural of anecdote is not data. ~ Roger Brinner > The combination of some data and an aching desire for an answer does not > ensure that a reasonable answer can be extracted from a given body of data. > ~ John Tukey > /////////////////////////////////////////////////////////////////////////////////////////// > > <https://www.inbo.be> > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel