[Rd] Feature request: Allow comma after last element in a list
Josiah Parry
jo@|@h@p@rry @end|ng |rom gm@||@com
Fri Apr 24 17:51:05 CEST 2026
It may be a bit overkill, but {vctrs} has really nice behavior here:
> vctrs::vec_c(1, 2, 3, )
[1] 1 2 3
On Fri, Apr 24, 2026 at 8:06 AM <avi.e.gross using gmail.com> wrote:
> Manfred,
>
> I don't know how much work it would be to add in a feature that was not in
> the original design of S at a time when perhaps a dangling comma was not
> supported widely or seen as necessary.
>
> I note that R (as a successor to S) kept the same convention here and a
> comma at the end of a line signals there is more to come and the parser
> should keep looking on additional lines for more to include within the same
> statement. This is different than a language like Python where indentation
> is used for a level of grouping and other methods are often used to
> indicate
> the current line should be extended.
>
> I wonder if a work-around might make sense. What if we allowed use of a
> symbol like "..." to mean not that there is more, but that it can be
> ignored
> if at the end of a series of commas.
>
> Something like:
>
> Hello <- c(
> "hi",
> "shalom".
> ... )
>
> Might then allow extension by adding a line before the ..., or perhaps even
> be set so any line with a ... is ignored. But this might take careful
> consideration. For example, when the interpreter reads in lines, it should
> not keep extra entries containing the "..." and you may need to check this
> does not break other things as my choice of ... is a valid symbol used
> elsewhere. Perhaps `%...%` or some unique symbol might serve the purpose,
> as
> it is just syntactic sugar.
>
> But, on the scale of things, this is not a must.
>
> -----Original Message-----
> From: R-devel <r-devel-bounces using r-project.org> On Behalf Of Manfred
> Kooistra
> Sent: Friday, April 24, 2026 5:09 AM
> To: r-devel using r-project.org
> Subject: [Rd] Feature request: Allow comma after last element in a list
>
> I've always been irritated that R doesn't allow a comma after the last
> element in a "list":
>
> > a <- c(
> + 1,
> + 2,
> + 3
> + )
> > a
> [1] 1 2 3
> > b <- c(
> + 1,
> + 2,
> + 3,
> + )
> Error in c(1, 2, 3, ) : argument 4 is empty
>
> This makes updating lists unnecessarily cumbersome, which I find I
> frequently do, either when I test code and want to run it with lists of
> varying elements or varying orders of elements or when I maintain lists
> manually over time and have to add or delete elements from them.
>
> Is there a reason for this behavior in R and might it not be a good idea to
> change it?
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
[[alternative HTML version deleted]]
More information about the R-devel
mailing list