R中找不到对象“ array.index”;从Reddit提取json数据

时间:2018-10-25 21:55:32

标签: arrays r json

我是编码的新手,如果这个问题很明显,我深表歉意,如果您需要更多信息,请告诉我。

我正在尝试在R中运行以下代码以从Reddit中提取json数据,并遇到以下错误消息,以获取代码的最后部分(#下面的代码#对于每个注释提取... );具体来说,我收到的消息是: filter(。,array.index == i)错误:找不到对象'array.index'

有人可以告诉我我的编码哪里出问题了吗?我已经尝试过:用array_index替换array.index,用array.index = i替换array.index == i。请让我知道,非常感谢您的帮助。

# Find the level of the nested json object where the comment data is
    comms<- res %>% enter_object("data") %>% 
        enter_object("children") %>% 
        gather_array() 

# Prepare empty dataframe with all needed columns
    df <- data.frame(id = character(), subreddit_id = character(),link_id = character(), 
                     parent_id = character(), created_utc = numeric(), author = character(), 
                     author_flair_text = character(),  body = character())

# Helper function to extract needed values from json object
    spread_vars<- function(json.df) {spread_values(json.df, id = jstring("id"),
                                                   subreddit_id = jstring("subreddit_id"),
                                                   link_id = jstring("link_id"),
                                                   parent_id = jstring("parent_id"),
                                                   created_utc = jnumber("created_utc"),
                                                   author = jstring("author"),
                                                   author_flair_text = jstring("author_flair_text"),
                                                   body = jstring("body"))}

# For each comment extract the needed values and add as row to the data frame
    for (i in 1:nrow(comms)) 
        {df <- do.call(rbind, list(df, comms %>% filter(array.index ==i) %>% 
                                   enter_object("data") %>% 
                                   spread_vars() %>% 
                                   select(-array.index, -document.id)))}

0 个答案:

没有答案