Skip to content

Commit

Permalink
prepare CRAN
Browse files Browse the repository at this point in the history
add return value doc, usethis::use_logo, update description, add NEWS.md, use github links
  • Loading branch information
polettif committed Jan 31, 2024
1 parent 0021ea5 commit 100bc7e
Show file tree
Hide file tree
Showing 33 changed files with 97 additions and 17 deletions.
12 changes: 8 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ Package: proporz
Type: Package
Title: Proportional Apportionment
Version: 1.3.1
Author: Flavio Poletti
Maintainer: Flavio Poletti <[email protected]>
Description: Calculate seat apportionment for legislative bodies using
different established methods, including biproportional apportionment.
Authors@R: c(
person("Flavio", "Poletti", role = c("cre", "cph"), email = "[email protected]"))
Description: Calculate seat apportionments for legislative bodies with
various methods. Methods inlcude divisor methods (e.g. D'Hondt, Webster or
Adams), quota methods (e.g. 'largest remainder method') and biproportional
apportionment.
License: GPL (>=3)
Encoding: UTF-8
LazyData: true
Expand All @@ -17,3 +19,5 @@ Suggests:
testthat,
shiny,
shinyMatrix
URL: https://github.com/polettif/proporz
BugReports: https://github.com/polettif/proporz/issues
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# proporz 1.3.2

* Added a `NEWS.md` file to track changes to the package.
2 changes: 2 additions & 0 deletions R/S3.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ as.matrix.proporz_matrix = function(x, ...) {
#' @param biproportional_result a matrix created by \code{\link{biproportional}}
#' or a data.frame created by \code{\link{pukelsheim}}
#'
#' @returns The district and party divisors in a list
#'
#' @examples
#' votes_matrix = matrix(c(51,60,63,98,100,102,45,120,144), nrow = 3)
#' district_seats = 4:6
Expand Down
10 changes: 8 additions & 2 deletions R/biproportional.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
#'
#' @seealso \code{\link{biproportional}}, \code{\link{divisors}}
#'
#' @returns A data.frame (like votes_df) with a new column denoting the number
#' seats per party and district
#'
#' @examples
#' # Zug 2018
#' votes_df = unique(zug2018[c("list_id", "entity_id", "list_votes")])
Expand Down Expand Up @@ -143,6 +146,9 @@ pukelsheim = function(votes_df, district_seats_df,
#' @seealso \code{\link{pukelsheim}} for usage with data frames.
#' \code{\link{divisors}} to access the divisors
#'
#' @returns Matrix with the same dimension as \code{votes_matrix} containing
#' the number of seats
#'
#' @examples
#' votes_df = unique(zug2018[c("list_id", "entity_id", "list_votes")])
#' votes_matrix = pivot_to_matrix(votes_df)
Expand Down Expand Up @@ -277,7 +283,7 @@ biproporz = biproportional
#'
#' @seealso \code{\link{biproportional}}, \code{\link{lower_apportionment}}
#'
#' @return named list with column/district seats and row/party seats
#' @returns A named list with column/district seats and row/party seats
#' @export
upper_apportionment = function(votes_matrix, district_seats,
use_list_votes = TRUE,
Expand Down Expand Up @@ -356,7 +362,7 @@ upper_apportionment = function(votes_matrix, district_seats,
#' @note The iterative process in the lower apportionment is only guaranteed to
#' terminate with Sainte-Laguë/Webster method.
#'
#' @return seat matrix with column and row divisors stored in attributes
#' @returns A seat matrix with column and row divisors stored in attributes
#'
#' @seealso \code{\link{biproportional}}, \code{\link{lower_apportionment}}
#'
Expand Down
9 changes: 8 additions & 1 deletion R/divisor.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#' @param divisors sequence of divisors. If it's a single number, a sequence
#' is generated starting with it.
#'
#' @inherit proporz return
#'
#' @export
highest_averages_method = function(party_votes, n_seats, divisors) {
check_votes_vector(party_votes, deparse(substitute(party_votes)))
Expand Down Expand Up @@ -53,6 +55,7 @@ highest_averages_method = function(party_votes, n_seats, divisors) {
#' German equivalent "Höchstzahlverfahren".
#'
#' @inheritParams highest_averages_method
#'
#' @export
hzv = function(party_votes, n_seats, divisors) {
highest_averages_method(party_votes, n_seats, divisors)
Expand All @@ -64,7 +67,7 @@ hzv = function(party_votes, n_seats, divisors) {
#'
#' @inheritParams proporz
#' @seealso \code{\link{proporz}}
#'
#' @inherit proporz return
#' @export
divisor_floor = function(votes, n_seats, quorum = 0) {
check_votes_vector(votes, deparse(substitute(votes)))
Expand All @@ -79,6 +82,7 @@ divisor_floor = function(votes, n_seats, quorum = 0) {
#'
#' @inheritParams proporz
#' @seealso \code{\link{proporz}}
#' @inherit proporz return
#' @export
divisor_round = function(votes, n_seats, quorum = 0) {
check_votes_vector(votes, deparse(substitute(votes)))
Expand All @@ -93,6 +97,7 @@ divisor_round = function(votes, n_seats, quorum = 0) {
#'
#' @inheritParams proporz
#' @seealso \code{\link{proporz}}
#' @inherit proporz return
#' @export
divisor_harmonic = function(votes, n_seats, quorum = 0) {
check_votes_vector(votes, deparse(substitute(votes)))
Expand All @@ -111,6 +116,7 @@ divisor_harmonic = function(votes, n_seats, quorum = 0) {
#'
#' @inheritParams proporz
#' @seealso \code{\link{proporz}}
#' @inherit proporz return
#' @export
divisor_geometric = function(votes, n_seats, quorum = 0) {
check_votes_vector(votes, deparse(substitute(votes)))
Expand All @@ -129,6 +135,7 @@ divisor_geometric = function(votes, n_seats, quorum = 0) {
#'
#' @inheritParams proporz
#' @seealso \code{\link{proporz}}
#' @inherit proporz return
#' @export
divisor_ceiling = function(votes, n_seats, quorum = 0) {
check_votes_vector(votes, deparse(substitute(votes)))
Expand Down
2 changes: 2 additions & 0 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#' Names can be used in [proporz()] or [biproportional()], the list entries
#' denote the actual implementation.
#'
#' @details
#' \code{list(
#' "divisor_floor" = "floor",
#' "d'hondt" = "floor",
Expand All @@ -27,6 +28,7 @@
#' "quota_largest_remainder" = "quota_largest_remainder"
#' )}
#'
#' @returns Named list of methods
#' @export
apport_methods = list(
"divisor_floor" = "floor",
Expand Down
2 changes: 2 additions & 0 deletions R/proporz.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#' \item{huntington-hill, hill-huntington, geometric (use \code{\link{divisor_geometric}})}
#' \item{hare-niemeyer, hamilton, vinton, quota_largest_remainder (use \code{\link{quota_largest_remainder}})}
#' }
#' @returns The number of seats per party as a vector
#'
#' @examples
#' votes = c("Party A" = 651, "Party B" = 349, "Party C" = 50)
#'
Expand Down
1 change: 1 addition & 0 deletions R/quota.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#'
#' @inheritParams proporz
#' @seealso \code{\link{proporz}}
#' @inherit proporz return
#' @export
quota_largest_remainder = function(votes, n_seats, quorum = 0) {
check_votes_vector(votes, deparse(substitute(votes)))
Expand Down
4 changes: 2 additions & 2 deletions R/shinyapp.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#'
#' @param votes_matrix optional votes_matrix to load upon start
#' @param district_seats optional district_seats to load upon start
#'
#' @returns Calling the function starts the shiny app
#' @examples
#' if(interactive()){
#' # You need to have shiny and shinyMatrix installed to run the app
#' # You need to have the packages 'shiny' and 'shinyMatrix' installed to run the app
#' run_app()
#'
#' # It's possible to load a matrix with the app
Expand Down
3 changes: 2 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ bisect = function(f, x1, x2, tol = 1e-9) {
#' @note This function exists because I wanted to have no dependencies.
#' Wrangling with reshape isn't fun at all and it became glaringly
#' apparent why better tools like tidyr exist
#' @returns a matrix
#' @export
pivot_to_matrix = function(df) {
stopifnot(ncol(df) == 3)
Expand All @@ -39,7 +40,7 @@ pivot_to_matrix = function(df) {
#'
#' @param matrix_wide matrix in wide format
#' @param value_colname name for the data.frame new column
#'
#' @returns data.frame with 3 columns
#' @export
pivot_to_df = function(matrix_wide, value_colname = "values") {
if(is.null(dimnames(matrix_wide))) {
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# proporz <img src="data-raw/proporz-hexsticker.png" align="right" height="140"/>
# proporz <img src="man/figures/logo.png" align="right" height="138" />

Calculate seat apportionment for legislative bodies using different established
methods, including biproportional apportionment.
Calculate seat apportionments for legislative bodies with various methods.
Methods inlcude divisor methods (e.g. D'Hondt, Webster or Adams), quota methods
(e.g. largest remainder method) and biproportional apportionment.

_Mit diesem R-Package können mittels verschiedener Sitzzuteilungsverfahren
Wählerstimmen in Abgeordnetensitze umgerechnet werden. Das Package beinhaltet
Expand Down Expand Up @@ -177,7 +178,7 @@ and `shinyMatrix` installed.
library(proporz)
run_app()
```
<img src="data-raw/shinyapp-example.gif" style = "width:70%;">
<img src="man/figures/shinyapp-example.gif" style = "width:70%;">

<br/>

Expand Down
Binary file removed data-raw/proporz-hexsticker.pdf
Binary file not shown.
Binary file removed data-raw/proporz-hexsticker.png
Binary file not shown.
3 changes: 3 additions & 0 deletions man/apport_methods.Rd

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

4 changes: 4 additions & 0 deletions man/biproportional.Rd

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

4 changes: 4 additions & 0 deletions man/biproporz.Rd

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

3 changes: 3 additions & 0 deletions man/divisor_ceiling.Rd

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

3 changes: 3 additions & 0 deletions man/divisor_floor.Rd

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

3 changes: 3 additions & 0 deletions man/divisor_geometric.Rd

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

3 changes: 3 additions & 0 deletions man/divisor_harmonic.Rd

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

3 changes: 3 additions & 0 deletions man/divisor_round.Rd

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

3 changes: 3 additions & 0 deletions man/divisors.Rd

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

Binary file added man/figures/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
3 changes: 3 additions & 0 deletions man/highest_averages_method.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/lower_apportionment.Rd

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

3 changes: 3 additions & 0 deletions man/pivot_to_df.Rd

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

3 changes: 3 additions & 0 deletions man/pivot_to_matrix.Rd

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

3 changes: 3 additions & 0 deletions man/proporz.Rd

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

4 changes: 4 additions & 0 deletions man/pukelsheim.Rd

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

3 changes: 3 additions & 0 deletions man/quota_largest_remainder.Rd

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

5 changes: 4 additions & 1 deletion man/run_app.Rd

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

Loading

0 comments on commit 100bc7e

Please sign in to comment.