meysubb / collegeballR

College Sports Data (R Package)
16 stars 4 forks source link

fixed the cfb_df #4

Closed rlindholm closed 5 years ago

rlindholm commented 5 years ago

Looks like you might have updated the name of the df recently. This gets the function working again.

meysubb commented 5 years ago

Oh yeah totally forgot about this, thanks for checking this.

meysubb commented 5 years ago

@rlindholm pt_id is the conversion of play_type. See line 31/33. It handles the conversion regardless.

rlindholm commented 5 years ago

Sorry, still working on that one, trying to fix this function call:

cfb_pbp_data(week=8, team='Florida State', year=2018) Error in paste0(play_base_url, "year=", year, "&week=", week, "&playType=", : object 'pt_id' not found

rlindholm commented 5 years ago

It only enters that first statement if play_type is not null. With a call with a null play_type, pt_id never gets set and it breaks.

meysubb commented 5 years ago

Oh yeah, I see that now. fixing it right now.

meysubb commented 5 years ago

I'm going to merge this and then make the change to fix that.

rlindholm commented 5 years ago

I've got one more fix in that function hang on one sec.

meysubb commented 5 years ago

just hit me with it on here, and i'll do it on my git branch

rlindholm commented 5 years ago

 if (is.null(play_type) & is.null(team)) {
    # no play type, no team
    full_url <- paste0(play_base_url, "year=", year, "&week=", week)
  } else{
    #team, no play_type
    if (is.null(play_type)) {
      full_url <-
        paste0(play_base_url,
               "year=",
               year,
               "&week=",
               week,
               "&team=",
               URLencode(team, reserved = T))
    } else if (is.null(team)) {
      # no team, play_type
      full_url <-
        paste0(
          play_base_url,
          "year=",
          year,
          "&week=",
          week,
          "&playType=",
          URLencode(play_type, reserved = T)
        )
    } else{
      # team & play type
      full_url <-
        paste0(
          play_base_url,
          "year=",
          year,
          "&week=",
          week,
          "&team=",
          URLencode(team, reserved = T),
          "&playType=",
          play_type
        )
    }
  }

  raw_play_df <- fromJSON(full_url)
  raw_play_df <- do.call(data.frame, raw_play_df)
  play_df <- raw_play_df

  return(play_df)
}```

The way it is currently, it's passing in null params. After the play_type fix it wasn't correctly bringing back Florida State's week 8. It was bringing back week 8 for a different team.
meysubb commented 5 years ago

Yep, I saw that too when debugging. Thanks for the help/debugging.

I'll update in a few minutes. I can add you on as a contributor on the pkg, just hit me with some details name/email.

rlindholm commented 5 years ago

Sure! Ryan Lindholm and ryan.lindholm@outlook.com. Thanks!