pkgdown/index.md

rdb

CRAN Status{.pkgdown-release}

rdb provides access to the Referendum Database (RDB) from R. This database aims to record all direct democratic votes worldwide and is operated by the Centre for Democracy Studies Aarau (ZDA) at the University of Zurich, Switzerland.

Installation

To install the latest development version of rdb, run the following in R:

if (!("remotes" %in% rownames(installed.packages()))) {
  install.packages(pkgs = "remotes",
                   repos = "https://cloud.r-project.org/")
}

remotes::install_gitlab(repo = "zdaarau/rpkgs/rdb")

Usage

An introduction to this package is given here. The (function) reference is found here.

Package configuration

Some of rdb's functionality is controlled via package-specific global configuration which can either be set via R options or environment variables (the former take precedence). This configuration includes:

::: table-wide Description R option Environment variable Default value

RDB Services API username rdb.api_username R_RDB_API_USERNAME RDB Services API password rdb.api_password R_RDB_API_PASSWORD Maximal timespan to preserve the package's pkgpins cache. Cache entries older than this will be deleted upon package loading. rdb.global_max_cache_age R_RDB_GLOBAL_MAX_CACHE_AGE "30 days" Whether or not to use the testing servers instead of the production servers for RDB Services API calls etc. rdb.use_testing_server R_RDB_USE_TESTING_SERVER FALSE Whether or not to run the tests that use the testing servers for RDB Services API calls etc. during devtools::test(). rdb.test_testing_server R_RDB_TEST_TESTING_SERVER FALSE :::

Development

R Markdown format

This package's source code is written in the R Markdown file format to facilitate practices commonly referred to as literate programming. It allows the actual code to be freely mixed with explanatory and supplementary information in expressive Markdown format instead of having to rely on # comments only.

All the .gen.R suffixed R source code found under R/ is generated from the respective R Markdown counterparts under Rmd/ using pkgpurl::purl_rmd()[^1]. Always make changes only to the .Rmd files -- never the .R files -- and then run pkgpurl::purl_rmd() to regenerate the R source files.

Coding style

This package borrows a lot of the Tidyverse design philosophies. The R code adheres to the principles specified in the Tidyverse Design Guide wherever possible and is formatted according to the Tidyverse Style Guide (TSG) with the following exceptions:

As far as possible, these deviations from the TSG plus some additional restrictions are formally specified in pkgpurl::default_linters, which is (by default) used in pkgpurl::lint_rmd(), which in turn is the recommended way to lint this package.

[^1]: The very idea to leverage the R Markdown format to author R packages was originally proposed by Yihui Xie. See his excellent blog post for his point of view on the advantages of literate programming techniques and some practical examples. Note that using pkgpurl::purl_rmd() is a less cumbersome alternative to the Makefile approach outlined by him.

[^2]: The TSG explicitly instructs to avoid this operator -- presumably because it's relatively unknown and therefore might be confused with the forward pipe operator %>% when skimming code only briefly. I don't consider this to be an actual issue since there aren't many sensible usage patterns of %>% at the beginning of a pipe sequence inside a function -- I can only think of creating side effects and relying on R's implicit return of the last evaluated expression. Therefore -- and because I really like the %<>% operator -- it's usage is welcome.

[^3]: The TSG explicitly accepts -> for assignments at the end of a pipe sequence while Google's R Style Guide considers this bad practice because it "makes it harder to see in code where an object is defined". I second the latter.



zdaarau/c2d documentation built on Dec. 18, 2024, 1:24 p.m.