我遇到一个奇怪的行为(如果我重新启动Rstudio,此代码可以正常运行,但是如果我在另一个运行此错误的脚本运行后运行)。
使用xml2读取xml文件
root_players是一小块14行x 13列
查看代码
library(xml2)
library(tidyverse)
xml_filename <-"file.xml"
# Leer XML
datos <- read_xml(xml_filename)
meta_datos <- datos %>%
xml_attrs() %>%
t() %>%
as_tibble()
root_players <- xml_find_all(datos, '/SoccerFeed/Player') %>%
xml_attrs() %>%
map(~as_tibble(t(.))) %>%
bind_rows()
node_players <- xml_find_all(datos, '/SoccerFeed/Player') %>%
map(~.x %>%
xml_children() %>%
map(function(.y) {.y %>%
xml_attrs() %>%
t() %>%
as_tibble() %>%
mutate(n_passes = xml_text(.y))}) %>%
bind_rows())
#############################
# HERE ERROR APPEARS
############################
root_players <- root_players %>%
mutate(n = map(node_players, count) %>% unlist()) %>%
uncount(weights = n)
#########################
### ERROR TRACE
#########################
Error: Assigned data `eval(cols[[col]], .data, parent.frame())` must be compatible with existing data.
x Existing data has 14 rows.
x Assigned data has 363 rows.
i Only vectors of size 1 are recycled.
<error/tibble_error_assign_incompatible_size>
Assigned data `eval(cols[[col]], .data, parent.frame())` must be compatible with existing data.
x Existing data has 14 rows.
x Assigned data has 363 rows.
i Only vectors of size 1 are recycled.
Backtrace:
Run `rlang::last_trace()` to see the full context