Skip to content

possible bug problem load_sprint() function #299

@Jordan-Soria

Description

@Jordan-Soria

Hi again!
I founded this problem with this function this morning:

Image

With this edition was solved for me:

load_sprint_fixed <- function(season, round){

url <- paste0("https://api.jolpi.ca/ergast/f1/",season,"/",round,"/sprint.json?limit=40")

data <- jsonlite::fromJSON(url, simplifyVector = F)

races <- data$MRData$RaceTable$Races

if(length(races) == 0){
message("No sprint data for season=",season," round=",round)
return(NULL)
}

results <- races[[1]]$SprintResults

df <- dplyr::bind_rows(lapply(results, function(x){

data.frame(
driverId = x$Driver$driverId,
constructorId = x$Constructor$constructorId,
position = x$position,
grid = x$grid,
laps = x$laps,
status = x$status,
points = x$points,
gap = ifelse(is.null(x$Time$time), NA, x$Time$time),
fastest = ifelse(is.null(x$FastestLap$Time$time), NA, x$FastestLap$Time$time)
)

}))

tibble::as_tibble(df)
}

Now work:

Image

Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions