Hi again!
I founded this problem with this function this morning:
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:
Cheers!
Hi again!
I founded this problem with this function this morning:
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:
Cheers!