From @nto|ne@|@br| @end|ng |rom gm@||@com  Thu Mar  2 18:49:52 2023
From: @nto|ne@|@br| @end|ng |rom gm@||@com (Antoine Fabri)
Date: Thu, 2 Mar 2023 18:49:52 +0100
Subject: [Rd] transform.data.frame() ignores unnamed arguments when no named
 argument is provided
Message-ID: <CAEKh8ug=Vy=rDkqCEKnrGL4h7A7fPmF_zpcwq2CTybNmOTgNnw@mail.gmail.com>

Dear r-devel,

See below:


transform(data.frame(a = 1), 2, 3)

#>   a

#> 1 1


transform(data.frame(a = 1), b=2, 3)

#>   a b X3

#> 1 1 2  3


We need a small modification to make it work consistently, see below:


transform.data.frame <- function (`_data`, ...) {

  e <- eval(substitute(list(...)), `_data`, parent.frame())

  tags <- names(e)

  ## NEW LINE -----------------------------------------------

  if (is.null(tags)) tags <- character(length(e))

  inx <- match(tags, names(`_data`))

  matched <- !is.na(inx)

  if (any(matched)) {

    `_data`[inx[matched]] <- e[matched]

    `_data` <- data.frame(`_data`)

  }

  if (!all(matched))

    do.call("data.frame", c(list(`_data`), e[!matched]))

  else `_data`

}


transform(data.frame(a = 1), 2, 3)

#>   a X2 X3

#> 1 1  2  3

transform(data.frame(a = 1), b=2, 3)

#>   a b X3

#> 1 1 2  3


Thanks,


Antoine

	[[alternative HTML version deleted]]



[Rd] transform.data.frame() ignores unnamed arguments when no named argument is provided
Antoine Fabri