Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] names for tstrsplit results #1379

Closed
franknarf1 opened this issue Oct 6, 2015 · 1 comment
Closed

[Request] names for tstrsplit results #1379

franknarf1 opened this issue Oct 6, 2015 · 1 comment
Assignees
Milestone

Comments

@franknarf1
Copy link
Contributor

On SO, I found myself doing...

trial = c("9-5", "7-5", "13-3", "17-6")
wdays = c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
setDT(tstrsplit(trial, "-", type.convert=TRUE))[, 
  paste0(wdays[V2 + 1], " ", V1, ":00")
]

It would be nice if I could instead do

with( tstrsplit(trial, "-", type.convert=TRUE, list.names=TRUE), 
  paste0(wdays[V2 + 1], " ", V1, ":00")
)

so V1, V2, etc are the names in the result.

The list.names arg could be extended to specify other naming rules as well.

@DavidArenburg
Copy link
Member

DavidArenburg commented Aug 22, 2016

I'm wondering if a syntax such setDT(df)[, ":="(tstrsplit(x, ",", names = TRUE))] should be allowed too since now this is a named list? This will both save the effort of finding out apriory how many columns we supposed to get after the split and shorten the syntax

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants