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

vignette datatable-sd-usage.Rmd: erreur LHS of := isn't column names #45

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

Comments

@ChristianWia
Copy link
Collaborator

ChristianWia commented Jul 29, 2024

Quand j'ouvre la vignette -> datatable-sd-usage.Rmd et que j'éxécute le code R,
je bloque sur l'instructions (et les suivantes du même type):

> Teams[ , names(.SD) := lapply(.SD, factor), .SDcols = patterns('teamID')]

erreur LHS of := isn't column names

D'après vous où serait la faute ? syntaxe ? que faut il écrire à la place ?

> require(data.table)
> knitr::opts_chunk$set(
+   comment = "#",
+   error = FALSE,
+   tidy = FALSE,
+   cache = FALSE,
+   collapse = TRUE,
+   out.width = '100%',
+   dpi = 144
+ )
> .old.th = setDTthreads(1)
> load('Teams.RData')
> setDT(Teams)
> Teams
> 
> load('Pitching.RData')
> setDT(Pitching)
> Pitching
> Pitching[ , .SD]
> identical(Pitching, Pitching[ , .SD])
[1] TRUE
> # W: Wins; L: Losses; G: Games
> Pitching[ , .SD, .SDcols = c('W', 'L', 'G')]
> # teamIDBR: Team ID used by Baseball Reference website
> # teamIDlahman45: Team ID used in Lahman database version 4.5
> # teamIDretro: Team ID used by Retrosheet
> fkt = c('teamIDBR', 'teamIDlahman45', 'teamIDretro')
> # confirm that they're stored as `character`
> str(Teams[ , ..fkt])
Classes ‘data.table’ and 'data.frame':	2895 obs. of  3 variables:
 $ teamIDBR      : chr  "BOS" "CHI" "CLE" "KEK" ...
 $ teamIDlahman45: chr  "BS1" "CH1" "CL1" "FW1" ...
 $ teamIDretro   : chr  "BS1" "CH1" "CL1" "FW1" ...
 - attr(*, ".internal.selfref")=<externalptr> 

> Teams[ , names(.SD) := lapply(.SD, factor), .SDcols = patterns('teamID')]

Error in `[.data.table`(Teams, , `:=`(names(.SD), lapply(.SD, factor)),  : 
  LHS of := isn't column names ('character') or positions ('integer' or 'numeric')

> names(.SD)
NULL
> Teams[ , names(.SD)]
 [1] "yearID"         "lgID"           "teamID"         "franchID"      
 [5] "divID"          "Rank"           "G"              "Ghome"         
 [9] "W"              "L"              "DivWin"         "WCWin"         
[13] "LgWin"          "WSWin"          "R"              "AB"            
[17] "H"              "X2B"            "X3B"            "HR"            
[21] "BB"             "SO"             "SB"             "CS"            
[25] "HBP"            "SF"             "RA"             "ER"            
[29] "ERA"            "CG"             "SHO"            "SV"            
[33] "IPouts"         "HA"             "HRA"            "BBA"           
[37] "SOA"            "E"              "DP"             "FP"            
[41] "name"           "park"           "attendance"     "BPF"           
[45] "PPF"            "teamIDBR"       "teamIDlahman45" "teamIDretro" 
> Teams$teamID
   [1] BS1 CH1 CL1 FW1 NY2 PH1 RC1 TRO WS3 BL1 BR1 BR2 BS1 CL1 MID NY2 PH1 TRO
  [19] WS3 WS4 BL1 BL4 BR2 BS1 ELI NY2 PH1 PH2 WS5 BL1 BR2 BS1 CH2 HR1 NY2 PH1
  [37] PH2 BR2 BS1 CH2 HR1 KEO NH1 NY2 PH1 PH2 PH3 SL1 SL2 WS6 BSN CHN CN1 HAR
  [55] LS1 NY3 PHN SL3 BSN CHN CN1 HAR LS1 SL3 BSN CHN CN1 IN1 ML2 PRO BFN BSN....
@ChristianWia
Copy link
Collaborator Author

C'est pareil chez vous ?

Suivi => Rdatatable/data.table#6321

@phgrosjean
Copy link
Owner

@ChristianWia Si tu utilises une vignette d'une version différente de celle de {data.table} que tu utilises pour la co=mpiler et que tu tombes sur une erreur, regardes déjà le fichier NEWS.md. Pour data.table [v1.15.99] (in development), new features nbr 6, il est indiqué : "Using dt[, names(.SD) := lapply(.SD, fx)] now works, Rdatatable/data.table#795 -- one of our Rdatatable/data.table#3189." Donc, la vignette a bien été mise à jour pour la v1.15.99 et ne fonctionne logiquement pas pour une version antérieure. Je clôture donc l'issue. Il n'y a pas de bug ici.

@ChristianWia
Copy link
Collaborator Author

J'ajoute ici les 2 commandes pour charger les packages non pas de CRAN mais du développement GitHub afin que cela serve à ceux qui voudront avoir la version en développement qui fait tourner le code contenu dans les vignettes du développement Master :

> library(devtools)
....
> install_github("Rdatatable/data.table")
... transform.data.table                    html  
    transpose                               html  
    truelength                              html  
    tstrsplit                               html  
    update_dev_pkg                          html  
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (data.table)
> 

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

2 participants