[Rd] paste(character(0), collapse="", recycle0=FALSE) should be ""

Gabriel Becker g@bembecker @end|ng |rom gm@||@com
Sun May 24 02:48:14 CEST 2020


Brodie,

A good point, but more analogous to what I'm concerned with is

> sum(5, numeric(0))

[1] 5


Not 0 (the analogu of Herve's desired behavior).

Best,
~G

PS Brodie sorry for the double.

On Fri, May 22, 2020 at 6:12 PM brodie gaslam <brodie.gaslam using yahoo.com>
wrote:

> > On Friday, May 22, 2020, 6:16:45 PM EDT, Hervé Pagès <
> hpages using fredhutch.org> wrote:
> >
> > Gabe,
> >
> > It's the current behavior of paste() that is a major source of bugs:
> >
> >   ## Add "rs" prefix to SNP ids and collapse them in a
> >   ## comma-separated string.
> >   collapse_snp_ids <- function(snp_ids)
> >       paste("rs", snp_ids, sep="", collapse=",")
> >
> >   snp_groups <- list(
> >     group1=c(55, 22, 200),
> >     group2=integer(0),
> >     group3=c(99, 550)
> >   )
> >
> >   vapply(snp_groups, collapse_snp_ids, character(1))
> >   #            group1            group2            group3
> >   # "rs55,rs22,rs200"              "rs"      "rs99,rs550"
> >
> > This has hit me so many times!
> >
> > Now with 'collapse0=TRUE', we finally have the opportunity to make it do
> > the right thing. Let's not miss that opportunity.
> >
> > Cheers,
> > H.
>
> FWIW what convinces me is consistency with other aggregating functions
> applied
> to zero length inputs:
>
> sum(numeric(0))
> ## [1] 0
>
> >
> >
> > On 5/22/20 11:26, Gabriel Becker wrote:
> > > I understand that this is consistent but it also strikes me as an
> > > enormous 'gotcha' of a magnitude that 'we' are trying to avoid/smooth
> > > over at this point in user-facing R space.
> > >
> > > For the record I'm not suggesting it should return something other than
> > > "", and in particular I'm not arguing that any call to paste /that does
> > > not return an error/ with non-NULL collapse should return a character
> > > vector of length one.
>

	[[alternative HTML version deleted]]



More information about the R-devel mailing list