Skip to content

Commit

Permalink
updated some examples in the readme, added news, and fixed a detail i…
Browse files Browse the repository at this point in the history
…n the vignette
  • Loading branch information
martigso committed Sep 11, 2023
1 parent 36ddf05 commit bfa7e3a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 33 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# stortingscrape 0.1.4

* Fixed some typos in the readme
* Reworked the `read_obt()` function for the package not to rely on `dplyr`
* Added a hex badge logo. Extremely important.

# stortingscrape 0.1.3

* IMPORTANT: Fixed an issue with `get_mp_bio()`, which broke after [an API update](https://data.stortinget.no/nyhetsoversikt/endringer-i-biografidata/).
Expand Down
47 changes: 34 additions & 13 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,63 @@ weaving together different parts of the data.stortinget.no API.

## Installation

The package can be installed either by cloning this repository and building the package in R or
by installing via the `devtools::install_github()` function:
### CRAN (stable version)

The latest stable version of the `stortingscrape` package can be installed from
by running CRAN:

```{r, eval=FALSE}
install.packages("stortingscrape")
```

### Github (development version)

The development version of the package can be installed either by cloning this
repository and building the package in R or by installing via the
`devtools::install_github()` function:

```{r install, eval=FALSE}
devtools::install_github("martigso/stortingscrape")
library(stortingscrape)
```

## Usage example
## Usage examples

Request all interpellations for a parliamentary session:

```{r usage_ex, eval=FALSE}
sessions <- get_parlsessions()
qsesh <- get_session_questions(sessions$id[9], q_type = "interpellasjoner")
library(stortingscrape)
library(pbmcapply) # for progress bar. never use paralell on scraping
parl_sessions |> # sessions data are built into the package
head() # but can also be retrieved with `get_parlsessions()`
int1213 <- pbmclapply(qsesh$id, function(x){
get_question(x, good_manners = 2)
qsesh <- get_session_questions(parl_sessions$id[9], q_type = "interpellasjoner")
}, mc.cores = 1) # do not increase number of cores!
for(i in qsesh$id) {
message("Getting ", i)
int1213[[i]] <- get_question(i, good_manners = 2)
}
int1213 <- do.call(rbind, int1213)
head(int1213)
```

Get biographies of all MPs for a given parliamentary period (will take ~30min to run):

```{r usage_ex2, eval=FALSE}
parl_periods <- get_parlperiods()
parl_periods # parliamentary periods (4 years) are built into the package,
# but can also be retrieved with `get_parlperiods()`
mps <- get_parlperiod_mps(parl_periods$id[1], substitute = TRUE)
mps_bios <- pbmclapply(mps$id, function(x) get_mp_bio(x, good_manners = 2), mc.cores = 1) # do not increase number of cores!
mps_bios <- lapply(mps$mp_id, get_mp_bio, good_manners = 2)
# Expand by all periods the MP has been in parliament
mps_periods <- lapply(mps_bios, function(x){
Expand Down Expand Up @@ -91,8 +111,9 @@ mps_positions <- do.call(rbind, mps_positions)

## Data description

The data is described in detail in the [API of Stortinget](https://data.stortinget.no/dokumentasjon-og-hjelp/). The package will implement English translations of this documentation in the future.
The data is described in detail in the
[API of Stortinget](https://data.stortinget.no/dokumentasjon-og-hjelp/).

## List of functions currently implemented
## Functions

[You can find a list of all functions here.](https://martigso.github.io/stortingscrape/functions.html)
51 changes: 34 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,62 @@ data.stortinget.no API.

## Installation

The package can be installed either by cloning this repository and
building the package in R or by installing via the
`devtools::install_github()` function:
### CRAN (stable version)

The latest stable version of the `stortingscrape` package can be
installed from by running CRAN:

``` r
install.packages("stortingscrape")
```

### Github (development version)

The development version of the package can be installed either by
cloning this repository and building the package in R or by installing
via the `devtools::install_github()` function:

``` r
devtools::install_github("martigso/stortingscrape")
library(stortingscrape)
```

## Usage example
## Usage examples

Request all interpellations for a parliamentary session:

``` r
sessions <- get_parlsessions()
qsesh <- get_session_questions(sessions$id[9], q_type = "interpellasjoner")
library(stortingscrape)

library(pbmcapply) # for progress bar. never use paralell on scraping
parl_sessions |> # sessions data are built into the package
head() # but can also be retrieved with `get_parlsessions()`

int1213 <- pbmclapply(qsesh$id, function(x){

get_question(x, good_manners = 2)
qsesh <- get_session_questions(parl_sessions$id[9], q_type = "interpellasjoner")

}, mc.cores = 1) # do not increase number of cores!
for(i in qsesh$id) {

message("Getting ", i)

int1213[[i]] <- get_question(i, good_manners = 2)

}

int1213 <- do.call(rbind, int1213)

head(int1213)
```

Get biographies of all MPs for a given parliamentary period (will take
\~30min to run):
~30min to run):

``` r
parl_periods <- get_parlperiods()
parl_periods # parliamentary periods (4 years) are built into the package,
# but can also be retrieved with `get_parlperiods()`

mps <- get_parlperiod_mps(parl_periods$id[1], substitute = TRUE)

mps_bios <- pbmclapply(mps$id, function(x) get_mp_bio(x, good_manners = 2), mc.cores = 1) # do not increase number of cores!
mps_bios <- lapply(mps$mp_id, get_mp_bio, good_manners = 2)

# Expand by all periods the MP has been in parliament
mps_periods <- lapply(mps_bios, function(x){
Expand Down Expand Up @@ -93,11 +112,9 @@ mps_positions <- do.call(rbind, mps_positions)
## Data description

The data is described in detail in the [API of
Stortinget](https://data.stortinget.no/dokumentasjon-og-hjelp/). The
package will implement English translations of this documentation in the
future.
Stortinget](https://data.stortinget.no/dokumentasjon-og-hjelp/).

## List of functions currently implemented
## Functions

[You can find a list of all functions
here.](https://martigso.github.io/stortingscrape/functions.html)
3 changes: 0 additions & 3 deletions vignettes/stortingscrape.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,6 @@ votes, and more.

<!-- # Computational details -->




# List of functions {#app:functions}

A list of all functions and their description can be found in the package
Expand Down

0 comments on commit bfa7e3a

Please sign in to comment.