Learn R Programming

permutations (version 1.0-2)

valid: Functions to validate permutations

Description

Functions to validate permutation objects.

Function singleword.valid() takes an integer vector, interpreted as a word, and checks that it is a permutation of seq_len(max(x)).

Function cycle.valid() takes a cyclist and checks for disjoint cycles of strictly positive integers with no repeats.

Usage

singleword_valid(w)
cyclist_valid(x)

Arguments

x

In function cycle_valid(), a cyclist

w

In function singleword_valid(), an integer vector

Value

Returns either TRUE, or stops with an informative error message

See Also

cyclist

Examples

Run this code
# NOT RUN {
singleword_valid(sample(1:9))

# }
# NOT RUN {
singleword_valid(c(5,6,3,9,7,8,2,1))   # returns an error (no '4')
singleword_valid(c(5,6,3,4,9,7,8,2,1)) # returns an error (not integer)
# }
# NOT RUN {
cyclist_valid(list(c(1,8,2),c(3,6))) # should be TRUE
singleword_valid(c(5L,6L,3L,4L,9L,7L,8L,2L,1L)) # should be TRUE

# }
# NOT RUN {
cyclist_valid(list(c(1,8,2),c(8,6))) # returns an error ('8' is repeated)
# }

Run the code above in your browser using DataLab