createPowerset: Create powerset

View source: R/createPowerset.R

createPowersetR Documentation

Create powerset

Description

Given a vector of elements generate a power set.

Usage

createPowerset(
  elements,
  includeEmptySet = TRUE,
  result = c("return", "print", "copy", "printCompact", "copyCompact")
)

Arguments

elements

vector of elements

includeEmptySet

If TRUE, an empty vector is added at the end

result

What to do with the result. Can be either:

  • "return": return list object

  • "print": create valid string to call PowerRelation() or as.PowerRelation() and print it

  • "copy": create valid string to call PowerRelation() or as.PowerRelation() and copy it to clipboard

  • "printCompact" and "copyCompact": same as "print" and "copy" but without newlines

Value

List of power set vectors. If the parameter result is set to "print" or "copy", nothing is returned. Instead, a character string is generated that can be used in R to call and create a new PowerRelation object. This string is either printed or copied to clipboard (see argument result).

Examples

# normal return type is a list of vectors
createPowerset(c("Alice", "Bob"), includeEmptySet = FALSE)
## [[1]]
## [1] "Alice" "Bob"
##
## [[2]]
## [1] "Alice"
##
## [[3]]
## [1] "Bob"

# instead of creating a list, print the power set such that it can be copy-pasted
# and used to create a new PowerRelation object
createPowerset(letters[1:4], result = "print")
# prints
# as.PowerRelation("
#   abcd
#   > abc
#   > abd
#   > acd
#   > bcd
#   > ab
#   ...
#   > {}
# ")

createPowerset(letters[1:3], includeEmptySet = FALSE, result = "printCompact")
# as.PowerRelation("abc > ab > ac > bc > a > b > c")

# create the same string as before, but now copy it to the clipboard instead
if(interactive()) {
  createPowerset(1:3, result = "copyCompact")
}

# Note that as.PowerRelation(character) only assumes single-char elements.
# As such, the generated function call string with multi-character names
# looks a little different.
createPowerset(c("Alice", "Bob"), result = "print")
# PowerRelation(rlang::list2(
#   list(c("Alice", "Bob")),
#   list(c("Alice")),
#   list(c("Bob")),
#   list(c()),
# ))


jassler/socialranking documentation built on March 29, 2025, 5:23 a.m.