Title: Create Unique Pseudonymous Animal Names
Version: 0.1.0
Description: Generate pseudonymous animal names that are delightful and easy to remember like the Likable Leech and the Proud Chickadee. A unique pseudonym can be created for every unique element in a vector or row in a data frame. Pseudonyms can be customized and tracked over time, so that the same input is always assigned the same pseudonym.
License: MIT + file LICENSE
Suggests: testthat, covr
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.1
URL: https://github.com/Teebusch/noah
BugReports: https://github.com/Teebusch/noah/issues
Imports: R6, hash, digest, assertthat, purrr, dplyr, magrittr, crayon, rlang, stringr
Depends: R (≥ 3.1.0)
NeedsCompilation: no
Packaged: 2021-01-14 10:47:54 UTC; teebu
Author: Tobias Busch ORCID iD [aut, cre]
Maintainer: Tobias Busch <teebusch@gmail.com>
Repository: CRAN
Date/Publication: 2021-01-18 09:10:06 UTC

Pipe operator

Description

See magrittr::%>% for details.

Usage

lhs %>% rhs

A pseudonym archive

Description

An Ark object can create and remember pseudonyms. Given the same input, it will always return the same pseudonym. No pseudonym will repeat.

Public fields

log

Hashtable for all used pseudonyms. Inputs (keys) are stored as hashes.

Methods

Public methods


Method new()

Create new ark object.

Usage
Ark$new(alliterate = FALSE, parts = NULL, seed = NULL)
Arguments
alliterate

Logical. Should the Ark return alliterations by default?

parts

List of character vectors with name parts to be used for the pseudonyms. Defaults to adjectives and animals.

seed

Random seed for permutation of name parts. Use this to make Ark reproducible (to the extent that the random number generation is reproducible). If NULL (default), the random number generator is left alone. This is a convenience argument and equivalent to calling set.seed() before creating the Ark.

Returns

A new Ark object.


Method pseudonymize()

Create Pseudonyms for input.

Usage
Ark$pseudonymize(..., .alliterate = NULL)
Arguments
...

One or more R objects.

.alliterate

Logical. Return only pseudonyms that are alliterations. Defaults to TRUE if the Ark was created with Ark$new(alliterate = TRUE), FALSE otherwise. If FALSE, pseudonyms may still be alliterations by coincidence.

Returns

Character vector of pseudonyms with same length as input.


Method print()

Pretty-print an Ark object.

Usage
Ark$print(n = NULL)
Arguments
n

A positive integer. The number of example pseudonyms to print.


Method length()

Number of used pseudonyms in an Ark.

Usage
Ark$length()

Method length_allit()

Number of used alliterations in an Ark.

Usage
Ark$length_allit()

Method clone()

The objects of this class are cloneable with this method.

Usage
Ark$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.


Add column with pseudonyms to a data frame

Description

Add column with pseudonyms to a data frame

Usage

add_pseudonyms(
  .data,
  ...,
  .name = "pseudonym",
  .before = NULL,
  .after = NULL,
  .ark = NULL
)

Arguments

.data

A data frame to add pseudonyms to.

...

Columns to use as keys on which pseudonyms should be based. Supports tidy select. If empty, all columns will be used.

.name

Name of the new column as string.

.before

<tidy-select> Destination of columns selected by .... Supplying neither will move columns to the left-hand side; specifying both is an error.

.after

<tidy-select> Destination of columns selected by .... Supplying neither will move columns to the left-hand side; specifying both is an error.

.ark

An Ark object. If NULL (default) a new Ark is created. Using an existing Ark makes sure that the same input returns the same pseudonym.

Value

A data frame with an additional column containing the pseudonyms.

Examples

add_pseudonyms(mtcars)

Cleans name parts for use by an Ark.

Description

Cleans name parts for use by an Ark.

Usage

clean_name_parts(parts)

Get the number of unused elements left in a random permutation

Description

Get the number of unused elements left in a random permutation

Usage

get_n_remaining(f)

Arguments

f

Function created by random_permutation()

Value

Integer, number of elements left in the permutation


Convert linear index to matrix subscripts

Description

Takes a vector of integers (1D linear indexed) and converts them to matrix subscripts in n-dimensional matrix. Modeled after MATLAB's ind2sub()

Usage

ind2subs(ind, dims)

Arguments

ind

An integer vector with linear indexes

dims

An n-dimensional integer vector. Each element of this vector indicates the size of the corresponding dimension in the n-dimensional matrixc.

Value

A list of n lists of equal length. Each list corresponds to one of the n dimensions of the matrix. Rows indicate subscripts. Suitable for use with mapping functions.


Coalescing infix OR operator

Description

Operator that provides default value for NULL. See op-null-default for details.


Create unique pseudonyms

Description

Pseudonymize returns unique pseudonyms for R objects. It accepts any number of vectors and data frame as arguments and will use them as keys for the pseudonym creation. Vectors and data frames must have identical length. Elements in the same position or row are treated as part of the same key. The same key is always assigned the same pseudonym. Different keys are always assigned different pseudonyms.

Usage

pseudonymize(..., .alliterate = NULL, .ark = NULL)

Arguments

...

One or multiple objects to use as keys for which pseudonyms should be created, usually one or more columns of a data frame. All objects must be of the same length.

.alliterate

Logical. Should only pseudonyms that are alliterations be returned? Defaults to FALSE, or TRUE if set as TRUE for the Ark provided to .ark. If set, takes precedence over the Ark's default setting.

.ark

An Ark object. If NULL (default) a new Ark is created. Using an existing Ark makes sure that the same input returns the same pseudonym.

Value

A character vector of pseudonyms.

Examples

pseudonymize("Mata Hari")

Generate a lazy non-repeating random number generator

Description

Generates a function that provides lazy number generation from a random permutation of integers 1 to n without repetition. The numbers are generated using the Fisher-Yates algorithm and run length encoding (RLE) is used to keep memory use for the storage of used/available numbers minimal.

Usage

random_permutation(n)

Arguments

n

Upper limit for random numbers (inclusive)

Value

A function f(m) that returns m random numbers from the random permutation of integers 1 to n without repetition,. If all available numbers 1 to n have been returned but more are requested, the function throws an error.


Remove numbers from a lazy non-repeating random number generator

Description

Modify the random permutation function f in order to remove numbers i from the numbers that are available in the random permutation

Usage

remove_remaining(f, i)

Arguments

f

Function created by random_permutation()

i

Integer vector of numbers that should be removed from remaining numbers in the random permutation that is produced by f

Value

A random permutation function which will not produce the numbers in i anymore.


Convert matrix subscripts to linear index

Description

Takes subscripts as list of lists or data frame and converts them to linear index.

Usage

subs2ind(subs, dims)

Arguments

subs

Subscripts as list of lists of data frame.

dims

An n-dimensional integer vector. Each element of this vector indicates the size of the corresponding dimension in the n-dimensional matrixc.

Value

In integer vector with linear indexes.

mirror server hosted at Truenetwork, Russian Federation.