Commit 7a17f0cb authored by Keisuke ANDO's avatar Keisuke ANDO 😌
Browse files

Add function to read rcl file

parents
.Rproj.user
.Rhistory
.RData
.Ruserdata
read_rcl <- function(path) {
rcl <- path |>
readr::read_lines() |>
tibble::as_tibble() |>
dplyr::mutate(
step = value |> stringr::str_extract("\\d+"),
agent = value |> stringr::str_extract("\\w+_([0-9]{1,2}|Coach)"),
team = agent |> stringr::str_remove("_([0-9]{1,2}|Coach)"),
unum = agent |> stringr::str_extract("([0-9]{1,2}|Coach)$"),
commands = value |>
stringr::str_extract("\\(.+\\)$") |>
purrr::map(~ .x |>
stringr::str_split("\\(|\\)", simplify = TRUE) |>
stringr::str_trim() |>
purrr::discard(~ .x == "")),
) |>
tidyr::unnest(commands) |>
dplyr::mutate(
commands = commands |> stringr::str_split("\\ ", n = 2),
command = commands |> purrr::map_chr(1),
args = commands |> purrr::map(~ .x[-1]),
) |>
dplyr::select(
step,
team,
unum,
command,
args,
line = value,
)
return(rcl)
}
---
title: "socceR"
output: github_document
---
### RCLファイルを読む関数ができました --- 使い方
```{r, message=FALSE, collapse = TRUE}
# tidyverseをインポートする
library(tidyverse)
# 作った関数を読み込む
source("R/read_rcl.R")
# ファイルを指定するだけ
read_rcl("data/20220304142841-HELIOS_base_1-vs-ThunderLeague_1.rcl")
```
\ No newline at end of file
socceR
================
### RCLファイルを読む関数ができました — 使い方
``` r
# tidyverseをインポートする
library(tidyverse)
# 作った関数を読み込む
source("R/read_rcl.R")
# ファイルを指定するだけ
read_rcl("data/20220304142841-HELIOS_base_1-vs-ThunderLeague_1.rcl")
## # A tibble: 485,911 x 6
## step team unum command args line
## <chr> <chr> <chr> <chr> <list> <chr>
## 1 0 HELIOS_base 1 init <chr [1]> "0,19\tRecv HELIOS_base_1: (init~
## 2 0 HELIOS_base 1 version <chr [1]> "0,19\tRecv HELIOS_base_1: (init~
## 3 0 HELIOS_base 1 goalie <chr [0]> "0,19\tRecv HELIOS_base_1: (init~
## 4 0 HELIOS_base 1 synch_see <chr [0]> "0,19\tRecv HELIOS_base_1: (sync~
## 5 0 HELIOS_base 1 ear <chr [0]> "0,19\tRecv HELIOS_base_1: (sync~
## 6 0 HELIOS_base 1 off <chr [1]> "0,19\tRecv HELIOS_base_1: (sync~
## 7 0 HELIOS_base 1 clang <chr [0]> "0,19\tRecv HELIOS_base_1: (sync~
## 8 0 HELIOS_base 1 ver <chr [1]> "0,19\tRecv HELIOS_base_1: (sync~
## 9 0 HELIOS_base 1 turn <chr [1]> "0,20\tRecv HELIOS_base_1: (turn~
## 10 0 HELIOS_base 1 turn_neck <chr [1]> "0,20\tRecv HELIOS_base_1: (turn~
## # ... with 485,901 more rows
```
This source diff could not be displayed because it is too large. You can view the blob instead.
Version: 1.0
RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment