[Rd] Feature request: Allow comma after last element in a list
Tomek Gieorgijewski
cybergeorge2020 @end|ng |rom gm@||@com
Thu Apr 30 19:44:14 CEST 2026
Hi Manfred!
As I can see that you already maintain the habit to have one element per
line,
I would like to propose that you incorporate some editing scripts in your
editor
to help ease your frustration.
I believe trying to change R parser will only add more of that feeling :)
I don't know your editor but if it's vim, I can propose this edit to .vimrc
file:
" ----
function! ListCommas() range
if a:firstline < a:lastline
" Add commas at the end from first to second to last line if
there's no comma yet
execute a:firstline . "," . (a:lastline - 1) . 's/[^,]$/&,/e'
endif
" Delete comma from last line (if matched)
execute a:lastline . 's/,$//e'
endfunction
vnoremap <leader>, :call ListCommas()<CR>
" ---
So, now if you rerun vim on your file you can swap, add, delete lines from
the list as you wish,
and at the end you can highlight all elements lines of your list in visual
mode and execute ListCommas
function on those lines with <leader>, shortcut.
Of course only if you maintain your structure of element per line and
trailing parenthesis at a seperate line.
I'm sure VS Code, Emacs and some other editors have similar abilities to
help you.
Unfortunately I don't know of any such possibility in RStudio.
regards,
Tomek.
pt., 24 kwi 2026 o 13:35 Manfred Kooistra <manfred.kooistra using gmail.com>
napisał(a):
> 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
>
[[alternative HTML version deleted]]
More information about the R-devel
mailing list