dfs-with-r / coach

Lineup optimization for daily fantasy sports
https://dfs-with-r.github.io/coach/
GNU General Public License v3.0
47 stars 13 forks source link

Having issues with write_lineups #6

Closed jsst28 closed 5 years ago

jsst28 commented 5 years ago

I'm assuming I'm missing something when I try to use the write_lineups function. I either get: "Error in split.default(lineups, lineups[["lineup"]]) : group length is 0 but data length > 0" or "Error: '...' used in an incorrect context"

I feel like an idiot for asking, but what should I placing with regards to the "NULL" and after the comma within this code. I've tried everything I can think of and can't figure it out. write_lineups(lineups, path = NULL, ...)

zamorarr commented 5 years ago

Hey @jsst28 - no worries about not knowing, I should probably (and will) add an example of how to use it in the README.

The path argument is just specifying where you want to save the file on your computer. So it should be something like this:

write_lineups(mylineups, path = "/home/user/mydata.csv")

or if you are on Windows

write_lineups(mylineups, path = "C:\My Documents\mylineups.csv")

Does that help or are you still getting an error? If you are still having trouble paste the command you are using in here and I'll try and help debug.

jsst28 commented 5 years ago

I'm still getting an error. I've tried doubling the backward slashes but that didn't work and neither did trying to use file.path.

write_lineups(lineups, path = "C:\My Documents\lineups.csv") Error: '\M' is an unrecognized escape in character string starting ""C:\M"

write_lineups(lineups, path = "C:\My Documents\lineups.csv") Error in split.default(lineups, lineups[["lineup"]]) : group length is 0 but data length > 0

write_lineups(lineups, file.path = 'c:','My Documents','lineups.csv') Error in split.default(lineups, lineups[["lineup"]]) : group length is 0 but data length > 0

zamorarr commented 5 years ago

Yep the first error in the list you posted is due to not using double backwards slashes. The third one won't work because there is no argument called file.path in the function. The second one looks good but apparently there is some issue with the lineups data. Can you paste the first few rows of lineups? Also what sport and dfs optimizer did you use?

jsst28 commented 5 years ago

I'm using FD NHL Optimizer. Here's the first tibble: lineups [[1]]

A tibble: 9 x 8

row_id player_id player team position salary fpts_avg fpts_proj

1 39 32918-8475 Travis Zajac NJ C 4000 11.0 12.1 2 46 32918-14565 Mika Zibanejad NYR C 7400 17.5 18.9 3 82 32918-42993 Rasmus Ristolainen BUF D 4900 15.9 15.9 4 171 32918-37881 Morgan Rielly TOR D 6200 17.0 17.7 5 182 32918-15400 Petr Mrazek CAR G 8000 24.0 24.6 6 223 32918-8403 Justin Williams CAR W 5700 19.0 19.0 7 224 32918-12728 Nino Niederreiter CAR W 6300 18.9 19.0 8 262 32918-70913 Luke Kunin MIN W 3400 10.6 11.0 9 321 32918-43214 Nikita Kucherov TB W 9100 30.1 28.9
zamorarr commented 5 years ago

Ok! I'm able to reproduce the error. I've made a quick fix. Can you re-install the package using my new fix?

devtools::install_github("dfs-with-r/coach", ref = "fix-write-lineups")

Then something like this should work. You have to specify the site and sport in the new function.

library(coach)
nhl <- read_fd("salaries.csv")
model <- model_fd_nhl(nhl)
lineups <- optimize_generic(nhl, model)

write_lineups(lineups, "mylineups.csv", site = "fanduel", sport = "nhl")
zamorarr commented 5 years ago

The output should look like this. The order of the positions is important (C,C,W,W,W,W,D,D,G)

C C W W W W D D G
23625-58926 23625-8535 23625-8718 23625-12410 23625-62723 23625-66675 23625-8426 23625-8467 23625-8612
23625-58926 23625-8535 23625-43214 23625-12410 23625-62723 23625-66675 23625-8426 23625-8467 23625-8612
23625-58926 23625-8535 23625-12410 23625-37968 23625-79857 23625-79820 23625-9015 23625-8467 23625-8612
jsst28 commented 5 years ago

That fixed the issue! Thank you very much!