Title: | Handle Strings as Vectors of Characters |
---|---|
Description: | Creates a new chars class which looks like a string but is actually a vector of individual characters, making 'strings' iterable. This class enables vector operations on 'strings' such as reverse, sort, head, and set operations. |
Authors: | Jonathan Carroll [aut, cre] |
Maintainer: | Jonathan Carroll <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.6 |
Built: | 2024-11-08 10:23:35 UTC |
Source: | CRAN |
chars
ObjectExtract or Replace Parts of a chars
Object
## S3 method for class 'chars' x[...]
## S3 method for class 'chars' x[...]
x |
a |
... |
further arguments passed to or from other methods. |
the extracted parts of a chars
object, or a chars
object with
replacements performed.
s <- chars("censor") s[2:5] s[2:5] <- "X" s
s <- chars("censor") s[2:5] s[2:5] <- "X" s
chars
ObjectsCombine chars
Objects
## S3 method for class 'chars' c(...)
## S3 method for class 'chars' c(...)
... |
|
a larger chars
object containing the combined elements of ...
.
c(chars("java"), chars("script"))
c(chars("java"), chars("script"))
chars
ObjectCreate a chars
Object
chars(x, ...)
chars(x, ...)
x |
object to convert to |
... |
other options passed to methods. |
an object of class chars
.
chars
Object From a StringCreate a chars
Object From a String
## S3 method for class 'character' chars(x, ...)
## S3 method for class 'character' chars(x, ...)
x |
string to convert to a |
... |
unused |
chars
expects a single string as input. To create a list of these,
consider lapply(strings, chars)
an object of class chars
, essentially splitting the string into
individual characters
chars
Convert an Object to chars
## Default S3 method: chars(x, ...)
## Default S3 method: chars(x, ...)
x |
object to convert |
... |
other options |
.NotYetImplemented()
error
Count Characters in a Chars Object
count(x, value, ignore.case = FALSE)
count(x, value, ignore.case = FALSE)
x |
A vector of characters. |
value |
character (length 1) to count |
ignore.case |
should the letter case be ignored? |
integer, count of instances of value
in x
count(chars("strawberry"), 3)
count(chars("strawberry"), 3)
Does not treat the operation as a set.
except(x, y)
except(x, y)
x |
larger vector. |
y |
smaller vector. |
elements of x
not appearing in y
.
except(c(1:5), 3) except(chars("abcde"), "c") except(chars("abracadabra"), "b")
except(c(1:5), 3) except(chars("abcde"), "c") except(chars("abracadabra"), "b")
chars
ObjectFormat a chars
Object
## S3 method for class 'chars' format(x, ...)
## S3 method for class 'chars' format(x, ...)
x |
a |
... |
further arguments passed to or from other methods. |
a formatted chars
object.
chars
ObjectReturn the First Parts of a chars
Object
## S3 method for class 'chars' head(x, ...)
## S3 method for class 'chars' head(x, ...)
x |
a |
... |
further arguments passed to or from other methods. |
the first (n
) elements of a chars
object as a chars
object.
head(chars("abcdefhgi")) head(chars("javascript"), 4)
head(chars("abcdefhgi")) head(chars("javascript"), 4)
chars
ObjectsSetwise Intersection of chars
Objects
## S3 method for class 'chars' intersect(x, y, ...)
## S3 method for class 'chars' intersect(x, y, ...)
x |
a |
y |
a |
... |
further arguments passed to or from other methods. |
the setwise intersection of x
and y
.
union(chars("pine"), chars("apple"))
union(chars("pine"), chars("apple"))
A combination of is_letter()
and is_number()
.
is_alnum(x)
is_alnum(x)
x |
A vector of characters. |
A boolean vector indicating whether each element of x
is a
letter or a number.
is_alnum(chars("Lee7c0deR 4 L1fe")) Filter(is_alnum, chars("2 B or !2 B"))
is_alnum(chars("Lee7c0deR 4 L1fe")) Filter(is_alnum, chars("2 B or !2 B"))
Compares against the values of letters
(the English alphabet),
ignoring case.
is_letter(x)
is_letter(x)
x |
A vector of characters. |
A boolean vector indicating whether each element of x
is a
letter (appears in letters
ignoring case).
is_letter(chars("Lee7c0deR")) Filter(is_letter, chars("w00t"))
is_letter(chars("Lee7c0deR")) Filter(is_letter, chars("w00t"))
Compares against the values of 0:9
(as a number).
is_number(x)
is_number(x)
x |
A vector of characters. |
A boolean vector indicating whether each element of x
is a
number (appears in 0:9
as a number)
is_number(chars("Lee7c0deR")) Filter(is_number, chars("w00t"))
is_number(chars("Lee7c0deR")) Filter(is_number, chars("w00t"))
Compares against the regex group [[:punct:]]
.
is_punct(x)
is_punct(x)
x |
A vector of characters. |
A boolean vector indicating whether each element of x
is
considered as punctuation.
is_punct(chars("I can haz?")) Filter(Negate(is_punct), chars("abc,123;$*%?"))
is_punct(chars("I can haz?")) Filter(Negate(is_punct), chars("abc,123;$*%?"))
chars
ObjectPrint a chars
Object
## S3 method for class 'chars' print(x, ...)
## S3 method for class 'chars' print(x, ...)
x |
a |
... |
further arguments passed to or from other methods. |
x
(invisibly), used to print to console.
chars
ObjectReverse Elements of a chars
Object
## S3 method for class 'chars' rev(x)
## S3 method for class 'chars' rev(x)
x |
a |
a chars
object with the elements reversed.
rev(chars("racecar")) rev(chars("alphabet"))
rev(chars("racecar")) rev(chars("alphabet"))
chars
ObjectsSetwise Difference Between chars
Objects
## S3 method for class 'chars' setdiff(x, y, ...)
## S3 method for class 'chars' setdiff(x, y, ...)
x |
a |
y |
a |
... |
further arguments passed to or from other methods. |
the setwise difference of x
and y
.
setdiff(chars("javascript"), chars("script"))
setdiff(chars("javascript"), chars("script"))
chars
ObjectSort a chars
Object
## S3 method for class 'chars' sort(x, decreasing = FALSE, ...)
## S3 method for class 'chars' sort(x, decreasing = FALSE, ...)
x |
a |
decreasing |
logical. Should the sort be increasing or decreasing? Not available for partial sorting. |
... |
further arguments passed to or from other methods. |
a sorted chars
object.
sort(chars("alphabet"))
sort(chars("alphabet"))
chars
ObjectCreate a String From a chars
Object
string(x, collapse = "", ...)
string(x, collapse = "", ...)
x |
one or more |
collapse |
an optional character string to separate the results. Not NA_character_. |
... |
other arguments passed to |
a character
(traditional R string) with the elements of x
in a single value.
chars
ObjectReturn the Last Parts of a chars
Object
## S3 method for class 'chars' tail(x, ...)
## S3 method for class 'chars' tail(x, ...)
x |
a |
... |
further arguments passed to or from other methods. |
the last (n
) elements of a chars
object as a chars
object.
tail(chars("javascript")) tail(chars("abcdefghi"))
tail(chars("javascript")) tail(chars("abcdefghi"))
chars
ObjectsSetwise Union of chars
Objects
## S3 method for class 'chars' union(x, y, ...)
## S3 method for class 'chars' union(x, y, ...)
x |
a |
y |
a |
... |
further arguments passed to or from other methods. |
the setwise union of x
and y
.
union(chars("java"), chars("script"))
union(chars("java"), chars("script"))
chars
Objects.Extract Unique Elements of chars
Objects.
## S3 method for class 'chars' unique(x, ...)
## S3 method for class 'chars' unique(x, ...)
x |
a |
... |
further arguments passed to or from other methods. |
a chars
object containing unique elements.
unique(chars("mississippi"))
unique(chars("mississippi"))