read_rcg.R 711 Bytes
Newer Older
1
#' Read RCG file
2
#'
3
4
#' @param path RCG file path
#' @return Parsed tibble of RCG file in \code{path}
5
#' @examples
6
7
#' read_rcg("data/20220405162804-HELIOS_base_3-vs-enemy_2.rcg")
read_rcg <- function(path) {
8
9
10
11
12
13
14
15
16
17
    rcg <- path |>
        readr::read_file() |>
        jsonlite::parse_json(simplifyVector = TRUE, flatten = TRUE) |>
        tibble::as_tibble() |>
        dplyr::filter(type == "show") |>
        dplyr::select(time, stime, players, ball.x, ball.y, ball.vx, ball.vy) |>
        tidyr::unnest(players) |>
        dplyr::select(time:capacity, ball.x:ball.vy) |>
        dplyr::rename(step = time) |>
        dplyr::rename_with(stringr::str_replace, pattern = "\\.", replacement = "_")
18

19
    return(rcg)
20
}