Wilcar Wilcar - 3 months ago 7
R Question

Unable to convert WikipediaR package object to dataframe

WikipediaR package offers a great function to list page's contributors.

Package configuration

install.packages("WikipediaR")
library (WikipediaR)


Collecting contribs R'page

contribs_r_page <- contribs(domain = "fr", page = "R")


The problem: How to convert my object contribs_r_page in a data.frame?

str (contribs_r_page)

List of 4
$ call : language contribs(page = "R", domain = "fr")
$ contribs :'data.frame': 219 obs. of 3 variables:
..$ user : Factor w/ 143 levels "0x010C","109.213.170.237",..: 87 73 121 9 121 64 11 81 47 121 ...
..$ userid : Factor w/ 111 levels "0","1017","1019240",..: 97 86 28 1 28 50 1 44 7 28 ...
..$ timestamp: Factor w/ 219 levels "2004-02-09T19:44:05Z",..: 219 218 217 216 215 214 213 212 211 210 ...
$ page : Named chr [1:3] "0" "50889" "fr"
..- attr(*, "names")= chr [1:3] "ns" "_idx" ""
$ testWikiPage:List of 4
..$ takeOnlyFirst: logi FALSE
..$ redirPage : NULL
..$ test : num 0
..$ warnMessage : NULL
- attr(*, "class")= chr "contribsClass"


What I tried:

contribs_r_page_df <- as.data.frame.list (contribs_r_page)

Answer

From the str output we can see contribs_r_page list object contains a data.frame named contribs, so we can just access it as below:

contribs_r_page$contribs