BillPetti / baseballr

A package written for R focused on baseball analysis. Currently in development.
billpetti.github.io/baseballr
Other
356 stars 98 forks source link

ind argument returns error in the fg_pitcher_leaders function #305

Closed aaronmorrisNC closed 1 year ago

aaronmorrisNC commented 1 year ago

Hello,

I am using RStudio version 2023.06.0 Build 421 and baseballR version 1.5.0. When running the following function data is returned and all is well

fg_pitcher_leaders (2022, 2024, league = "all", pitcher_type = "sta", ind = 1)

However, if I change the ind argument to "0" as follows

fg_pitcher_leaders (2022, 2024, league = "all", pitcher_type = "sta", ind = 0)

I get the following error

2023-06-15 13:34:18: Invalid arguments or no pitcher leaders data available!

image

camdenk commented 1 year ago

I believe the error is caused by the argument attempting to pull data from the 2024 season, which would be empty at this point.

aaronmorrisNC commented 1 year ago

I dug a bit deeper and modified that pitcher_type argument in addition to the ind argument.

fg_pitcher_leaders(2022, 2024, league = "all", pitcher_type = "rel", ind = 0) fg_pitcher_leaders(2022, 2024, league = "all", pitcher_type = "sta", ind = 0)

The first command doesn't error whereas the second does. So I don't think it is an issue with the 2024 value unless I am not seeing something.

image

camdenk commented 1 year ago

What's the end goal for this function call?

The data returned by the function seems to match what it would look like when directly input on the FanGraphs site, except for returning the error for Alcantara's single row when looking at SPs.

aaronmorrisNC commented 1 year ago

So it's my understanding that the ind = 0 argument aggregates the data for all seasons. I have a workaround but wanted to bring it to the attention of the authors.

camdenk commented 1 year ago

Yep, that's what it does. Because it's trying to aggregate stats for a season that hasn't happened yet, I it's running into issues with a lack of players reaching the "qualified" criteria.

If you set the qual = 0 (or some other reasonable target), it works as intended.

aaronmorrisNC commented 1 year ago

Appreciate the help @camdenk. I can confirm your suggestion works as intended.