Skip to content

iteratively constructing a json data frame makes problems on 'later' mutation #48

@behrica

Description

@behrica

I construct a json data frame in a loop, like this:

papers = data.frame()

for (....) {
 current_papers <- content %>% as.tbl_json %>%
                enter_object("items") %>% gather_array() %>%
                spread_values(title=jstring("title"),
                              snippet= jstring("snippet"),
                              link= jstring("link"),
                              displayLink=jstring("displayLink")) %>%
                enter_object("pagemap","metatags") %>% gather_array() %>%
                spread_values(creationdate=jstring(creationdate_field),
                              moddate=jstring(moddate_field)) 

            papers <- rbind(papers,current_papers)

}

this seems to work fine, (the data frame looks good)
but using "mutate" from dplyr on it, like this

papers <-
    papers %>%
    mutate(clickLink=paste0('=HYPERLINK("',link,'","link")'))

gives a very strange error message

Error in `$<-.data.frame`(`*tmp*`, "..JSON", value = list(list(author = "Microsoft Office User",  : 
  replacement has 9 rows, data has 40

Converting it to a dataframe first, does work:

  papers %>% data.frame() %>%
    mutate(clickLink=paste0('=HYPERLINK("',link,'","link")'))

Is this a bug in tidyjson or do I do something wrong ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions