Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix senadores #11

Merged
merged 4 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

Expand All @@ -47,3 +47,4 @@ jobs:
- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
86 changes: 0 additions & 86 deletions .github/workflows/roscron-check-standard.yaml

This file was deleted.

10 changes: 6 additions & 4 deletions .github/workflows/rostemplate-gh-pages.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
workflow_dispatch:
push:
branches: [main, master]
tags: ['*']

name: rostemplate-gh-pages
permissions: write-all

jobs:
rostemplate-gh-pages:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

Expand All @@ -31,6 +33,6 @@ jobs:

- name: Deploy package
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com"
Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE, run_dont_run = TRUE)'
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE, clean = TRUE, run_dont_run = TRUE)'
8 changes: 4 additions & 4 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
Expand All @@ -31,20 +31,20 @@ jobs:
covr::codecov(
quiet = FALSE,
clean = FALSE,
install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package")
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
shell: Rscript {0}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ VignetteBuilder:
knitr
Encoding: UTF-8
Language: en-US
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
2 changes: 1 addition & 1 deletion R/comisiones_ponencias.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' *Comisiones*
#'
#' Look up the *comisiones* and *ponencias* of a legislature.
#' Rellevant to know the code of the work groups.
#' Relevant to know the code of the work groups.
#' @inheritParams plenarias
#' @return A `data.frame` with the *comisiones* and *ponencias* of that legislature.
#' @export
Expand Down
40 changes: 27 additions & 13 deletions R/composicion.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,40 @@ grupos <- function(legislatura){
#'
#' Past and current appointed members.
#' @return A `data.frame` with the information available.
#' @inheritParams plenarias
#' @importFrom xml2 read_xml
#' @importFrom xml2 xml_text
#' @importFrom xml2 xml_find_all
#' @export
#' @examples
#' if (interactive()) {
#' head(senadores())
#' head(senadores(12))
#' }
senadores <- function() {
x <- read_xml(compose_url(tipoFich = 10))
s <- data.frame(nombre = xml_text(xml_find_all(x, "//senador/nombre")),
apellidos = xml_text(xml_find_all(x, "//senador/apellidos")),
legislatura = as.numeric(xml_text(xml_find_all(x, "//senador/legislatura"))),
ultCredencial = xml_text(xml_find_all(x, "//senador/ultCredencial")),
procedTipo = xml_text(xml_find_all(x, "//senador/procedTipo")),
procedLiteral = xml_text(xml_find_all(x, "//senador/procedLiteral")),
procedLugar = xml_text(xml_find_all(x, "//senador/procedLugar")),
grupoCod = xml_text(xml_find_all(x, "//senador/grupoCod")),
grupoSiglas = xml_text(xml_find_all(x, "//senador/grupoSiglas")),
grupoNombre = xml_text(xml_find_all(x, "//senador/grupoNombre")))
senadores <- function(legislatura = 12:14) {
stopifnot(!is.numeric(legislatura) || all(legislatura >= 0) || !is.null(legislatura))
senad_list <- lapply(legislatura, senadores_legis)
senad_df <- do.call(rbind, senad_list)
# The API return the same data twice
# Even there is a person LÓPEZ CONDÉS Legis = 3, ultCredencial 284 that is
# returned with accent and without it.
unique(senad_df)
}

# Converted from senadores, iterator
senadores_legis <- function(legislatura) {
x <- read_xml(compose_url(tipoFich = 10, legis = legislatura))
s <- data.frame(
nombre = xml_text(xml_find_all(x, "//senador/nombre")),
apellidos = xml_text(xml_find_all(x, "//senador/apellidos")),
legislatura = as.numeric(xml_text(xml_find_all(x, "//senador/legislatura"))),
ultCredencial = xml_text(xml_find_all(x, "//senador/ultCredencial")),
procedTipo = xml_text(xml_find_all(x, "//senador/procedTipo")),
procedLiteral = xml_text(xml_find_all(x, "//senador/procedLiteral")),
procedLugar = xml_text(xml_find_all(x, "//senador/procedLugar")),
grupoCod = xml_text(xml_find_all(x, "//senador/grupoCod")),
grupoSiglas = xml_text(xml_find_all(x, "//senador/grupoSiglas")),
grupoNombre = xml_text(xml_find_all(x, "//senador/grupoNombre"))
)
s$procedLugar <- gsub(pattern = ".+: ", "", s$procedLugar)
s$grupoCod <- gsub(pattern = ".+: ", "", s$grupoCod)
s$sex <- NA
Expand Down
2 changes: 1 addition & 1 deletion R/diario.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Retrieve the document of _sumario_
#'
#' Returns the summary of a session in a tidy way.
#' If multiple autors are involved in a disposicion and multiple documents they
#' If multiple authors are involved in a disposition and multiple documents they
#' get mixed.
#' @param cve The character of the CVE of the document.
#' @return A data.frame with a summary of the session, date, documents, authors.
Expand Down
2 changes: 2 additions & 0 deletions R/votos.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
#' @returns A votos class with information about who voted what.
#' @export
#' @examples
#' \donttest{
#' votos_64 <- votos(14, 64)
#' votos_3_8 <- votos(14, 3, 8)
#' }
votos <- function(legislatura, sesion, votacion = NULL) {
# if (!endsWith(x, ".xml")) {
# url <- paste0(force(BASE_URL), x)
Expand Down
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,27 @@ This function return the members of the Senate:
``` r
ts <- senadores()
head(ts)
#> nombre apellidos legislatura ultCredencial procedTipo
#> 1 FERNANDO ABAD BÉCQUER 5 260 D
#> 2 ENRIQUE ABAD BENEDICTO 10 034 E
#> 3 ELISABET ABAD GIRALT 12 051 D
#> 4 JOSÉ ANTONIO ABAD LÓPEZ-BREA 3 039 E
#> 5 PATRICIA ABASCAL JIMÉNEZ 14 199 E
#> 6 ADOLFO ABEJÓN ORTEGA 9 081 E
#> procedLiteral procedLugar grupoCod grupoSiglas
#> 1 Designado Asamblea de Madrid Asamblea de Madrid 800
#> 2 Electo Sevilla Sevilla 800
#> 3 Designada Parlamento de Cataluña Parlamento de Cataluña 807
#> 4 Electo Zamora Zamora CP
#> 5 Electa Eivissa-Formentera Eivissa-Formentera 800
#> 6 Electo Valladolid Valladolid 801
#> grupoNombre sex
#> 1 GPS male
#> 2 GPS male
#> 3 GPN female
#> 4 GPCP male
#> 5 GPS female
#> 6 GPP male
#> nombre apellidos legislatura ultCredencial procedTipo
#> 1 FERNANDO ABAD BÉCQUER 5 260 D
#> 2 ENRIQUE ABAD BENEDICTO 10 034 E
#> 3 ELISABET ABAD GIRALT 12 051 D
#> 4 JOSÉ ANTONIO ABAD LÓPEZ-BREA 3 039 E
#> 5 ADOLFO ABEJÓN ORTEGA 9 081 E
#> 6 FRANCISCO ABELLÁN MARTÍNEZ 9 242 D
#> procedLiteral procedLugar grupoCod
#> 1 Designado Asamblea de Madrid Asamblea de Madrid
#> 2 Electo Sevilla Sevilla
#> 3 Designada Parlamento de Cataluña Parlamento de Cataluña
#> 4 Electo Zamora Zamora
#> 5 Electo Valladolid Valladolid
#> 6 Designado Asamblea Regional de Murcia Asamblea Regional de Murcia
#> grupoSiglas grupoNombre sex
#> 1 800 GPS male
#> 2 800 GPS male
#> 3 807 GPN female
#> 4 CP GPCP male
#> 5 801 GPP male
#> 6 800 GPS male
```

We can see the increase of females on the Senate along the legislatures:
Expand Down
2 changes: 1 addition & 1 deletion man/comisiones.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified man/figures/README-senadoras-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions man/senadores.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/sumario.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/votos.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions vignettes/senadoRES.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ ts %>%
scale_y_continuous(breaks = seq(from = 0, to = 0.7, by = .1),
expand = expansion(add = c(0, 0.01)), limits = c(0, NA)) +
theme_minimal() +
labs(title = "Ratio of women", x = "Legislatura", y = "Ratio of women") +
guides(col = FALSE, shape = FALSE)
labs(title = "Ratio of women", x = "Legislatura", y = "Ratio of women")
```


Expand Down Expand Up @@ -107,7 +106,7 @@ sessions <- do.call(rbind, s)
ggplot(sessions) +
stat_sum(aes(sesionLegislatura, sesionHoraInicio,
fill = after_stat(n), size = 1), geom = "tile") +
guides(size = FALSE) +
guides(size = "none") +
theme_minimal() +
labs(title = "Hour of sessions", x = "Legislature", y = "Starting hour",
fill = "Sessions") +
Expand All @@ -119,7 +118,7 @@ So most of the times they meet at the afternoon.
If you want more detailed information of each session you can use the fichUrlDetalleSesion details:

```{r detalles}
details <- detalles(paste0("https://www.senado.es", sessions$fichUrlDetalleSesion[1]))
details <- detalles(paste0("https://www.senado.es", sessions$fichUrlDetalleSesion[3]))
details[1:5, c("asunto_id", "asunto_hora_inicio", "asunto_hora_fin", "punto_literal", "intervencion_orador_desc", "intervencion_orador_idWeb")]
```

Expand Down
Loading