Read-only mirror of https://github.com/statistikZH/eCHparser — Kanton Zürich. Issues & pull requests at the source.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Simon Graf 393696d22f
Merge pull request #26 from statistikZH/develop
eCH-0157 build functions
2026-05-12 08:58:09 +02:00
.github/workflows only on mondays and remove ubuntu "devel" 2025-10-16 09:45:37 +00:00
inst Add two testfiles to extdata 2026-05-11 16:47:45 +02:00
man Address style notes and update documentation 2026-05-12 08:52:03 +02:00
R Address style notes and update documentation 2026-05-12 08:52:03 +02:00
tests Update test data 2026-05-08 14:21:41 +02:00
.gitignore setup github actions via tic package 2024-10-25 12:11:07 +00:00
.Rbuildignore setup github actions via tic package 2024-10-25 12:11:07 +00:00
DESCRIPTION Bump version and create NEWS.md 2026-05-12 08:51:40 +02:00
eCHparser.Rproj Bug fix for all unnest_longer functions 2025-04-22 11:34:31 +00:00
LICENSE more renaming 2024-10-16 07:10:16 +00:00
LICENSE.md more renaming 2024-10-16 07:10:16 +00:00
NAMESPACE Finalise eCH_writer 2025-11-19 16:16:53 +00:00
NEWS.md Bump version and create NEWS.md 2026-05-12 08:51:40 +02:00
README.md Update README 2026-05-11 16:46:55 +02:00
README.Rmd Update README 2026-05-11 16:46:55 +02:00
tic.R setup github actions via tic package 2024-10-25 12:11:07 +00:00

eCHparser

tic License:
MIT

Convert XML files in the standardised formats of eCH-0252 and eCH-0157 into easy-to-use dataframes using the eCHparser package. The package also provides templates for election and candidate data, that can be easily turned into XML files in the eCH-0157 format. These files can be imported into the VOTING application.

Installation

You can install the development version of eCHparser from GitHub with:

# install.packages("devtools")
devtools::install_github("statistikZH/eCHparser")

Example: eCH-0252

The eCH-0252 standard is used to feed voting data from cantonal IT systems to the voteInfo API, which then uses the data to display (live) vote counting information, for example via the voteInfo App or the Results and Information Plattform of the Canton of Zurich.

The function parse_eCH_0252() allows users to transform these XML files to easy-to-use dataframes.

library(eCHparser)

# list all sample files
example_files <- system.file("extdata", package = "eCHparser") |>
  list.files()

# pick a random sample file
file <- sample(seq_along(example_files), 1)

# define filepath to sample file
filepath <- system.file("extdata", testfiles[file], package = "eCHparser")

# parse file, using only federal and cantonal votes
vote_df <- parse_eCH_0252(filepath, doi = c("CH", "CT"))

Example: eCH-0157

The eCH-0157 standard is used to import elections to and export elections from the IT systems used to manage election results management systems (i. e. VOTING in the canton of Zurich).

The function parse_eCH_0157() allows users to transform these XML files to easy-to-use dataframes.

library(eCHparser)

# list all sample files that contain 0252
example_files <- system.file("extdata", package = "eCHparser") |>
  list.files() |> 
  grep(pattern = "0252", x = _, value = TRUE)

# select the first of the files
file <- example_files[1]

# define filepath to sample file
filepath <- system.file(paste0("extdata/", file), package = "eCHparser")

# parse file, using only federal and cantonal votes
vote_df <- parse_eCH_0252(filepath, doi = c("CH", "CT"))

The function new_election_template() generates an XLSX template into which information about candidates can be entered. These templates can then be transformed into valid XML files in the format eCH-0157 using the function read_election_template() and either build_eCH_0157() to create the object in your R environment or write_eCH_0157() to directly write the XML file onto your disc. Alternatively, you can use the wrapper function convert_to_eCH_0157() to directly convert the XLSX file on your disk to the corresponding XML file.

library(eCHparser)

# list all XLSX sample files
example_files <- system.file("extdata", package = "eCHparser") |>
  list.files() |> 
  grep(pattern = "\\.xlsx$", x = _, value = TRUE)

# select the first of the files
file <- grep(pattern = "maj", example_files, value = TRUE)

# define filepath to sample file
filepath <- system.file(paste0("extdata/", file), package = "eCHparser")

# read the election template and add necessary data
election_df <- read_election_template(
  filepath,
  election_type = "Majority",
  date = "2030-01-01",
  election_title_short = "Test Election",
  election_title_long = "Test Election - Long Title",
  mandates = 5
)

# turn data into xml object, ready to be exported
election_xml <- build_eCH_0157(election_df, "Majority")