Package 'aleksandeR'

Title: Aleksander Bang-Larsen's personal convenience functions
Description: This package supplies all the convenience functions that I have written to make my life easier.
Authors: Aleksander Bang-Larsen [aut, cre, cph] (ORCID: <https://orcid.org/0009-0007-7984-4650>)
Maintainer: Aleksander Bang-Larsen <[email protected]>
License: AGPL (>= 3)
Version: 0.0.0.9005
Built: 2026-06-05 19:50:31 UTC
Source: https://github.com/aleksanderbl29/aleksandeR

Help Index


Format a number for presentation

Description

Format a number for presentation

Usage

format_num(
  x,
  decimals = 2,
  rounding = TRUE,
  big_mark = ".",
  decimal_mark = ","
)

Arguments

x

An integer/double value.

decimals

The amount of decimals the input x should be rounded to.

rounding

Whether or not the input x should be rounded. Excludes the use of the decimals argument.

big_mark

The thousand separator.

decimal_mark

The decimal separator.

Value

A number formatted correctly with two (default) decimals, a comma as the decimal separator and a period as the thousand-separator. The type is characther.

Examples

x <- pi
format_num(x)

format_num(x, 1)

format_num(x, rounding = FALSE)

List of parties up for election

Description

List of parties up for election

Usage

parties

Value

Returns a tibble with information on the major parties up for election

Source

https://www.valg.im.dk/partier-og-kandidater/opstillingsberettigede-partiers-adresser-mv

Examples

head(parties)

Create bibliography of {renv}-installed packages

Description

This was inspired by https://github.com/rstudio/renv/issues/340

Usage

pkg_bib(dependencies = FALSE, filename = "packages.bib", targets = FALSE)

Arguments

dependencies

Boolean to define how many packages are cited.

filename

Specify a filename/path for the .bib.

targets

Boolean to define if the bibliography should be created based on the packages defined in a targets pipeline and saved to ⁠_targets_packages.R⁠ by the function targets::tar_renv()

Value

Usually called for its side effect of a .bib written to the provided paths. Also outputs the package names in the console.


Get character count from ggplot2 object.

Description

Counts the number of characters in visible text elements from a ggplot2 plot. This also supports plots composed with patchwork, including collected guides.

Usage

plot_nchar(plot, debug = FALSE)

Arguments

plot

Input a ggplot2 object or a patchwork object.

debug

Logical. If TRUE, prints the text values that are counted.

Value

Returns an integer with the amount of characters in the plot. Spaces are included.

Examples

plot <- data.frame(
  x = seq(1, 10),
  y = seq(10, 1),
  label = rep(seq(1, 10, 2), 2)
  ) |>
  ggplot2::ggplot(ggplot2::aes(x = x, y = y, label = label)) +
  ggplot2::geom_text(nudge_y = 3)

plot_nchar(plot)

A theme made for maps from ggplot2::geom_map().

Description

This theme is made specifically for maps made with. A color-ready version exists as theme_map_color().

Usage

theme_map(base_size = 9, base_family = "")

Arguments

base_size

base font size, given in pts.

base_family

base font family


A color-ready theme made for maps from ggplot2::geom_map().

Description

This theme is made color-ready specifically for maps.

Usage

theme_map_color(
  color = "green",
  secondary_color = "pink",
  background_color = "black",
  base_size = 9,
  base_family = ""
)

Arguments

color

The primary color of the theme_map_color() plot. "Default is "green".

secondary_color

The secondary color of the theme_map_color() plot. Default is "pink".

background_color

The primary color of the theme_map_color() plot. Defaults is "black".

base_size

base font size, given in pts.

base_family

base font family