R Proficiency : Beginner
I'm trying to combine together dataframes from github issues api by following pages. But when I try to combine the last dataframe with the next one it gives me duplicate rownames error.
res <- GET(url,token,query = params)
resDF <- fromJSON(httr::content(res, as = "text"))
while (grepl("next", res$headers$link) == 'TRUE')
{
next_url = ifelse(grepl("prev", res$headers$link) == 'TRUE',
str_match(res$headers$link, 'rel="prev", <(.*)>; rel="next"')[1,2]
,
str_match(res$headers$link, '<(.*)>; rel="next"')[1,2]
)
#print(next_url)
next_res <- GET(next_url,token)
next_resDF <- fromJSON(httr::content(res, as = "text"))
resDF <- rbind(resDF, next_resDF)
}
Complete Error:
Warning message:
“non-unique values when setting 'row.names': ‘1’, ‘10’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’”
Error in `.rowNamesDF<-`(x, value = value): duplicate 'row.names' are not allowed
Traceback:
1. rbind(resDF, fromJSON(httr::content(res, as = "text")))
2. rbind(deparse.level, ...)
3. `rownames<-`(`*tmp*`, value = `*vtmp*`)
4. `row.names<-`(`*tmp*`, value = value)
5. `row.names<-.data.frame`(`*tmp*`, value = value)
6. `.rowNamesDF<-`(x, value = value)
7. stop("duplicate 'row.names' are not allowed")
I understand the error because with every api call the returned resDF will have rownames starting from 1
To handle this I tried increment the rownames of new DF by a counter
rownames(next_resDF) <- c("11", "12", "13", "14", "15"...)
Haven't been able to achieve this
Appreciate any helpful pointers