PatrickChodowski / NBAr

R package to interact with NBA api
6 stars 4 forks source link

errors from functions I've tried include `get_tracking` and `get_all_tracking` - errors due to `check_if_numeric` #9

Open fraupflaume opened 6 months ago

fraupflaume commented 6 months ago

When I run the functions get_tracking or get_all_tracking I'm returned the error [1] "Can't convert `replace` <double> to match type of `data` <character>." The problem stems from the internal call to check_if_numeric.

Here's code to make this reproducible.

library(NBAr)
get_tracking(season = 2023, type = "Player", measure_type = "Passing", 
             date_from = "02/07/2024", date_to = "02/07/2024")

When the function encounters a column that is all character data (e.g., player names) you'll get an error here, instead of a warning, due to the way it's used.

I would be remiss not to mention that mutate_if is deprecated, as well.

Although I did not explore all the ways this function is used, I was curious as to why type.convert() from the R utlils package wasn't used instead. (There may be a very good reason for that!)

I didn't do anything that I would consider a thorough examination, but using type.convert worked for me.

df3 <- data.frame(a = c("10", NA, 4), b = LETTERS[1:3], c = c(29, "2", 1)) %>% type.convert(as.is = T)
> lapply(df3, typeof)
$a
[1] "integer"

$b
[1] "character"

$c
[1] "integer"
PatrickChodowski commented 5 months ago

Hello, thank you for the issue and thorough review! I have to admit the package is kind of abandoned since I stopped using R and importing the data myself. I guess its good time to refresh it a bit - I will have a look and try to fix the issue.