fix vignettes
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
^doc$
|
||||
^Meta$
|
||||
@@ -1 +1,3 @@
|
||||
*.xml
|
||||
/doc/
|
||||
/Meta/
|
||||
|
||||
+3
-1
@@ -19,8 +19,10 @@ Imports:
|
||||
pbapply,
|
||||
rvest,
|
||||
stringr,
|
||||
tibble,
|
||||
xml2
|
||||
Suggests:
|
||||
rmarkdown,
|
||||
knitr
|
||||
knitr,
|
||||
ggplot2
|
||||
VignetteBuilder: knitr
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
# Generated by roxygen2: do not edit by hand
|
||||
|
||||
export(read_all)
|
||||
export(repair)
|
||||
import(dplyr)
|
||||
import(pbapply)
|
||||
import(stringr)
|
||||
import(tibble)
|
||||
import(utils)
|
||||
import(xml2)
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#' @import pbapply
|
||||
#' @import stringr
|
||||
#' @import xml2
|
||||
#' @import utils
|
||||
#' @keywords internal
|
||||
"_PACKAGE"
|
||||
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
# for usage see the example at the end
|
||||
|
||||
#' Parse xml records
|
||||
#'
|
||||
#' Creates a list of tibbles containing relevant information from all records
|
||||
#' stored in the input directory.
|
||||
#'
|
||||
#' @param path character
|
||||
#'
|
||||
#' @export
|
||||
read_all <- function(path="records/") {
|
||||
cat("Reading all records from", path, "\n")
|
||||
available_protocols <- list.files(path)
|
||||
|
||||
+3
-1
@@ -41,7 +41,9 @@ repair_talks <- function(talks) {
|
||||
talks
|
||||
}
|
||||
|
||||
# repairs all tables
|
||||
#' Repairs parsed tables
|
||||
#'
|
||||
#' @export
|
||||
repair <- function(parse_output) {
|
||||
list(redner = repair_redner(parse_output$redner),
|
||||
reden = repair_reden(parse_output$reden),
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/parse.R
|
||||
\name{read_all}
|
||||
\alias{read_all}
|
||||
\title{Parse xml records}
|
||||
\usage{
|
||||
read_all(path = "records/")
|
||||
}
|
||||
\arguments{
|
||||
\item{path}{character}
|
||||
}
|
||||
\description{
|
||||
Creates a list of tibbles containing relevant information from all records
|
||||
stored in the input directory.
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/repair.R
|
||||
\name{repair}
|
||||
\alias{repair}
|
||||
\title{Repairs parsed tables}
|
||||
\usage{
|
||||
repair(parse_output)
|
||||
}
|
||||
\description{
|
||||
Repairs parsed tables
|
||||
}
|
||||
@@ -14,23 +14,36 @@ knitr::opts_chunk$set(
|
||||
)
|
||||
```
|
||||
|
||||
```{r setup}
|
||||
library(hateimparlament)
|
||||
library(dplyr)
|
||||
library(ggplot2)
|
||||
```
|
||||
|
||||
## Preparation of data
|
||||
|
||||
First, you need to download all records of the current legislative period.
|
||||
```r
|
||||
read_all() %>% repair() -> res
|
||||
fetch_all("../records/") # path to directory where records should be stored
|
||||
```
|
||||
Second, those `.xml` files, need to be parsed into `R` `tibbles`. This is accomplished by:
|
||||
```{r}
|
||||
read_all("../records/") %>% repair() -> res
|
||||
|
||||
reden <- res$reden
|
||||
redner <- res$redner
|
||||
talks <- res$talks
|
||||
```
|
||||
We also used `repair` to fix a bunch of formatting issues in the records and unpacked
|
||||
the result into more descriptive variables.
|
||||
|
||||
# first tries
|
||||
## Analysis
|
||||
|
||||
Now we can start analysing our parsed dataset, e.g. find out which party gives the most talks:
|
||||
```{r}
|
||||
left_join(reden, redner, by=c("redner" = "id")) %>%
|
||||
group_by(fraktion) %>%
|
||||
summarize(n = n()) %>%
|
||||
ggplot(aes(x = fraktion, y = n)) +
|
||||
geom_bar(stat = "identity")
|
||||
```
|
||||
|
||||
|
||||
```{r setup}
|
||||
library(hateimparlament)
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user