Re: [Rd] bug in utils:::format.person

2023-06-05 Thread Kurt Hornik
> Achim Zeileis writes:

Thanks---Ivan's fix committed now with c84497.

Best
-k

> Apologies, I missed Ivan's fix to the problem (my day was too long...) 
> which is, of course, better than mine.

> On Sat, 3 Jun 2023, Achim Zeileis wrote:

>> 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.onkel...@inbo.be",
>>> comment = c(
>>> ORCID = "-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.onkel...@inbo.be",
>>> comment = c("c(ORCID = \"-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
>>> ctypenl_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.onkel...@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
>>> ///
>>> 
>>> 
>>> 
>>> [[alternative HTML version deleted]]
>>> 
>>> __
>>> R-devel@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>> __
>> R-devel@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>> 
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] bug in utils:::format.person

2023-06-02 Thread Achim Zeileis
Apologies, I missed Ivan's fix to the problem (my day was too long...) 
which is, of course, better than mine.


On Sat, 3 Jun 2023, Achim Zeileis wrote:


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.onkel...@inbo.be",
 comment = c(
   ORCID = "-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.onkel...@inbo.be",
  comment = c("c(ORCID = \"-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
ctypenl_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.onkel...@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
///



[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] bug in utils:::format.person

2023-06-02 Thread Achim Zeileis

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.onkel...@inbo.be",
 comment = c(
   ORCID = "-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.onkel...@inbo.be",
  comment = c("c(ORCID = \"-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
ctypenl_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.onkel...@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
///



[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] bug in utils:::format.person

2023-06-02 Thread Ivan Krylov
On Fri, 2 Jun 2023 16:55:59 +0200
Thierry Onkelinx via R-devel  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 =
'---', foo = 'bar bar bar bar bar')), style = 'R')
# [1] "person(given = c(\"J.\", \"Random\"),"
# [2] "   family = \"Hacker\","
# [3] "   comment = c(ORCID = \"---\", foo = \"bar
# bar bar bar bar\"))"
format(person(c('J.', 'Random'), 'Hacker', comment = c(ORCID =
'---', foo = 'bar bar bar bar bar bar')), style = 'R')
# [1] "person(given = c(\"J.\", \"Random\"),"
# [2] "   family = \"Hacker\","
# [3] "   comment = c(\"c(ORCID = \\\"---\\\", 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

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] bug in utils:::format.person

2023-06-02 Thread Thierry Onkelinx via R-devel
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.onkel...@inbo.be",
  comment = c(
ORCID = "-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.onkel...@inbo.be",
   comment = c("c(ORCID = \"-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
 ctypenl_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.onkel...@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
///



[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel