-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
105 lines (82 loc) · 3.73 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
dpi=200,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# ElectionsLATAM
<!-- Database Agnostic Package to Generate and Process 'SQL' Queries in R. -->
Allows the user to generate and execute select, insert, update and delete 'SQL' queries the underlying database without having to explicitly write 'SQL' code.
| Release | Usage | Development |
|:--------|:------|:------------|
|| [![minimal R version](https://img.shields.io/badge/R%3E%3D-4.0.0-blue.svg)](https://cran.r-project.org/) | [![R-CMD-check](https://github.com/rOpenStats/ElectionsLATAM/workflows/R-CMD-check/badge.svg)](https://github.com/rOpenStats/ElectionsLATAM/actions)|
| [![CRAN](http://www.r-pkg.org/badges/version/ElectionsLATAM)](https://cran.r-project.org/package=ElectionsLATAM) | | [![codecov](https://codecov.io/gh/rOpenStats/ElectionsLATAM/branch/master/graph/badge.svg)](https://app.codecov.io/gh/rOpenStats/ElectionsLATAM) |
|||[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)|
# How to get started
```R
# Not yet published in CRAN
# install.packages("ElectionsLATAM")
```
# How to get started (Development version)
Install the R package using the following commands on the R console:
```R
devtools::install_github("rOpenStats/ElectionsLATAM", build_opts = NULL)
```
# A simple example
To get started execute the following commands:
```{r, load}
# 0. Load libraries
library(ElectionsLATAM)
library(dplyr)
library(readr)
```
```{r, costa-rica}
# 1. Costa Rica
costa.rica.ein.path <- file.path(getPackageDir(), "costa-rica")
ecological.inference.calvo <- EcologicalInferenceStrategyCalvoEtAl$new()
costa.rica.ein <-
EcologicalInferenceProcessor$new(
ecological.inference.strategy = ecological.inference.calvo,
election.name = "2022-costa-rica-general-ballotage-n4",
scenario = "final",
data.input.path = costa.rica.ein.path,
input.file = "2021-generales_pivot_candidatos_n4.csv",
location.fields = c("id_unidad"),
votes.field = "votos",
#potential.votes.field = "habilitados",
ignore.fields = "habilitados",
col.types = cols(
.default = col_number(),
id_unidad = col_character()
)
)
dummy <- costa.rica.ein$loadInputPivotCandidatos()
costa.rica.ein$output.election <- readr::read_delim(
#ballotage.processor$pivot.filepath,
file.path(costa.rica.ein.path,
paste("2022-ballotage_pivot_candidatos_n4.csv", sep = "_")),
delim = ";",
col_types = cols(
.default = col_double(),
id_unidad = col_character()
)
)
costa.rica.ein$runScenario(include.blancos = TRUE, include.ausentes = TRUE,
max.potential.votes.rel.dif = 0.32)
costa.rica.test.path <- file.path(tempdir(), "test","costa-rica")
costa.rica.ein$exportBetab(output.folder = costa.rica.test.path, overwrite = TRUE)
dummy <- costa.rica.ein$generateOutputJSON(costa.rica.test.path,
filename = "balotaje_n4_ei.json")
costa.rica.ein$makeSankeyDiagram(output.path = costa.rica.test.path)
# Saving output table for reproducibility
# write_rds(costa.rica.ein$output.table, file.path(costa.rica.ein.path, "ein_2021_general_2022_ballotage.rds"))
```
# Troubleshooting
Please note that the 'ElectionsLATAM' project is released with a [Contributor Code of Conduct](https://github.com/rOpenStats/ElectionsLATAM/blob/master/CODE_OF_CONDUCT.md). By contributing to this project, you agree to abide by its terms.