parse1 <- function(x) {
line1 <- clean_lines[2 * x - 1]
line2 <- clean_lines[2 * x]
f1 <- str_trim(str_split(line1, "\\|")[[1]])
f2 <- str_trim(str_split(line2, "\\|")[[1]])
numpair <- as.integer(f1[1])
name <- f1[2]
points <- as.numeric(f1[3])
state <- f2[1]
pre_rating <- as.integer(str_extract(str_extract(f2[2], "R:\\s*\\d+"), "\\d+"))
rounded <- f1[4:10]
o <- rounded |>
str_extract("\\d+") |>
as.integer()
o <- o[!is.na(o)]
list(pair = numpair, name = name, state = state,
points = points, pre_rating = pre_rating, opponents = list(o))
}
n <- length(clean_lines) / 2
players <- lapply(seq_len(n), parse1)
players_df <- bind_rows(lapply(players, function(p) {
tibble(pair = p$pair, name = p$name, state = p$state,
points = p$points, pre_rating = p$pre_rating)
}))
head(players_df, 10)