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

problem with calling names(.SD) in data.table/vignettes/datatable-sd-usage.Rmd #6321

Closed
ChristianWia opened this issue Jul 29, 2024 · 3 comments

Comments

@ChristianWia
Copy link

Focussed on vignette translation i've open in Rstudio (Package data.table version 1.15.4) the actual datatable-sd-usage.Rmd (master here) and executed the R chunks but it stops when executing the new form with names(). Below i have also included old form showing := .SD .SDcols are operational (but were replaced in the latest version).

Where to look for ?

From .Rmd file :
.....The syntax to now convert these columns to factor is simple:

Teams[ , (fkt) := lapply(.SD, factor), .SDcols = fkt]
head(unique(Teams[[fkt[1L]]]))

[1] BOS CHI CLE KEK NYU ATH
101 Levels: ALT ANA ARI ATH ATL BAL BLA BLN BLU BOS ... WSN

Teams[ , names(.SD) := lapply(.SD, factor), .SDcols = patterns('teamID')]
# print out the first column to demonstrate success
head(unique(Teams[[fkt[1L]]]))

Erreur : LHS of := isn't column names ('character') or positions ('integer' or 'numeric')

@ChristianWia ChristianWia changed the title problem with calling names() in data.table/vignettes/datatable-sd-usage.Rmd problem with calling names(.SD) in data.table/vignettes/datatable-sd-usage.Rmd Jul 29, 2024
@MichaelChirico
Copy link
Member

that feature is not yet on CRAN so be sure to install from GitHub master first

@ben-schwen
Copy link
Member

We changed behavior and vignette in #4163

@ChristianWia
Copy link
Author

ok I had a lack of how-to. Sounds good now, I 've loaded the dvpt version :

> library("data.table")
data.table 1.15.99 IN DEVELOPMENT built 2024-07-29 17:39:54 UTC; Kriss using 1 threads (see ?getDTthreads).  Latest news: r-datatable.com

and i've got a concrete result now :

The syntax to now convert these columns to `factor` is simple:
{r assign_factors}
Teams[ , names(.SD) := lapply(.SD, factor), .SDcols = patterns('teamID')]
# print out the first column to demonstrate success
head(unique(Teams[[fkt[1L]]]))

[1] BOS CHI CLE KEK NYU ATH
101 Levels: ALT ANA ARI ATH ATL BAL BLA BLN BLU BOS BRA ....

So we can close the topic. Thanks all for your help.

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

No branches or pull requests

3 participants