问题映射和R中的嵌套数据

问题描述

我遇到一个奇怪的行为(如果我重新启动Rstudio,此代码可以正常运行,但是如果我在另一个运行此错误的脚本运行后运行)。

  1. 使用xml2读取xml文件

  2. root_players是一小块14行x 13列

enter image description here

  1. node_players是一些小贴士

enter image description here

  1. 映射和取消列出列表时出错(如果我重新启动R,此代码有效...但是运行其他代码后失败)

    enter image description here

会话信息

enter image description here

查看代码


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]],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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)