You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
shift give.names could apply auto-name logic to list() input #3905
to reduce number of NSE operations I would rather prefer to accept character vector to give.names, otherwise new names will look ugly for a on-the-fly computed elements
I think we could handle that in a more generic way. I recall some other places which could benefit from it as well. And one new coming in PR adding give.names to rolling functions.
The more generic way I have in mind is to pre-process j calls of form .(x, y) into calls .(x=x, y=y). Then input we supply to shift (or any other fun) is a named list, rather unnamed, and give.names will handle that. So no change to shift is needed. NSE (to substitute names of variables) is moved to [ where is a good place for it already.
Proof of concept seems to work, but we also need to handle list() not just .(), and this will likely be a breaking change when user defined functions relied on V1, etc names.
diff --git a/R/data.table.R b/R/data.table.R
index 473cf6e7..269a1555 100644
--- a/R/data.table.R
+++ b/R/data.table.R
@@ -94,7 +94,11 @@ replace_dot_alias = function(e) {
# . alias also used within bquote, #1912
if (e[[1L]] == 'bquote') return(e)
if (e[[1L]] == ".") e[[1L]] = quote(list)
- for (i in seq_along(e)[-1L]) if (!is.null(e[[i]])) e[[i]] = replace_dot_alias(e[[i]])
+ for (i in seq_along(e)[-1L]) if (!is.null(e[[i]])) {
+ if (is.name(e[[i]]) && is.null(names(e[i]))) {
+ names(e)[i] = as.character(e[[i]])
+ } else e[[i]] = replace_dot_alias(e[[i]])
+ }
}
e
}
Hi @MichaelChirico@jangorecki
I've been studying the proposal to pre-process .(x, y) into .(x=x, y=y) for auto-naming in give.names.
I understand this introduces a breaking change where shift(.(x, y), give.names=TRUE) would produce x_lag_1, y_lag_1 instead of V1_lag_1, V2_lag_1. While this affects existing code that relies on the V* naming, I believe users would prefer the more intuitive variable names.
Should we proceed with this breaking change and if so, would you like me to implement enhancement in replace_dot_alias() .
Activity
jangorecki commentedon Nov 30, 2019
to reduce number of NSE operations I would rather prefer to accept character vector to
give.names, otherwise new names will look ugly for a on-the-fly computed elementsMichaelChirico commentedon Dec 4, 2019
We should have some internal utilities for this, then there's no duplication/bifurcation of logic at least
jangorecki commentedon Sep 14, 2022
I think we could handle that in a more generic way. I recall some other places which could benefit from it as well. And one new coming in PR adding give.names to rolling functions.
The more generic way I have in mind is to pre-process j calls of form
.(x, y)into calls.(x=x, y=y). Then input we supply to shift (or any other fun) is a named list, rather unnamed, and give.names will handle that. So no change to shift is needed. NSE (to substitute names of variables) is moved to [ where is a good place for it already.jangorecki commentedon Sep 14, 2022
Proof of concept seems to work, but we also need to handle
list()not just.(), and this will likely be a breaking change when user defined functions relied on V1, etc names.diff
Mukulyadav2004 commentedon Jul 21, 2025
Hi @MichaelChirico @jangorecki
I've been studying the proposal to pre-process .(x, y) into .(x=x, y=y) for auto-naming in give.names.
I understand this introduces a breaking change where shift(.(x, y), give.names=TRUE) would produce x_lag_1, y_lag_1 instead of V1_lag_1, V2_lag_1. While this affects existing code that relies on the V* naming, I believe users would prefer the more intuitive variable names.
Should we proceed with this breaking change and if so, would you like me to implement enhancement in replace_dot_alias() .
MichaelChirico commentedon Jul 21, 2025
I reckon we're late enough in the dev cycle that we'd prefer not to add any more breaking changes in 1.18.0