Преглед на файлове

fix vignettes

genderequality-alternative
flavis преди 4 години
родител
ревизия
574480a9bb
променени са 10 файла, в които са добавени 68 реда и са изтрити 9 реда
  1. +2
    -0
      .Rbuildignore
  2. +2
    -0
      .gitignore
  3. +3
    -1
      DESCRIPTION
  4. +3
    -0
      NAMESPACE
  5. +1
    -0
      R/hateimparlament-package.R
  6. +8
    -0
      R/parse.R
  7. +3
    -1
      R/repair.R
  8. +15
    -0
      man/read_all.Rd
  9. +11
    -0
      man/repair.Rd
  10. +20
    -7
      vignettes/funwithdata.Rmd

+ 2
- 0
.Rbuildignore Целия файл

@@ -0,0 +1,2 @@
^doc$
^Meta$

+ 2
- 0
.gitignore Целия файл

@@ -1 +1,3 @@
*.xml
/doc/
/Meta/

+ 3
- 1
DESCRIPTION Целия файл

@@ -19,8 +19,10 @@ Imports:
pbapply,
rvest,
stringr,
tibble,
xml2
Suggests:
rmarkdown,
knitr
knitr,
ggplot2
VignetteBuilder: knitr

+ 3
- 0
NAMESPACE Целия файл

@@ -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)

+ 1
- 0
R/hateimparlament-package.R Целия файл

@@ -5,6 +5,7 @@
#' @import pbapply
#' @import stringr
#' @import xml2
#' @import utils
#' @keywords internal
"_PACKAGE"



+ 8
- 0
R/parse.R Целия файл

@@ -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
R/repair.R Целия файл

@@ -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),


+ 15
- 0
man/read_all.Rd Целия файл

@@ -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.
}

+ 11
- 0
man/repair.Rd Целия файл

@@ -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
}

+ 20
- 7
vignettes/funwithdata.Rmd Целия файл

@@ -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)
```

Loading…
Отказ
Запис