find_word: Find words that fit the chosen parameters.

Description Usage Arguments See Also Examples

Description

Uses regex constructed by model_to_regex to search words. By default the search is done among words.eng.
find_word returns a vector of found words, find_word_l returns a logical vector that can be used for subsetting.

Usage

1
2
3
4
5
find_word(model = "*", allow = letters, ban = character(0),
  type = "usual", words = wfindr::words.eng)

find_word_l(model = "*", allow = letters, ban = character(0),
  type = "usual", words = wfindr::words.eng)

Arguments

model

pattern that a word should match. Consists of letters and unknown characters specifications. Dot . stands for unknown character. It may be followed by {...} repetition quantifier (i.e. .{n}, .{n,}, .{n,m}). Asterisk * stands for unknown number of unknown characters. See examples.
By default model is set to "*".

allow

characters allowed to fill gaps in a word. Can be listed in a single string or in a vector. By default is set to letters.

ban

characters not allowed to fill gaps in a word.

type

can be "usual", "scrabble", or "anagram". Abbreviated input is allowed: e.g. "u", "s", or "a".
type defines how often allowed characters can be used to fill the gaps. Say, character appears n times in allow and m times in ban. If d = n - m is less or equal to zero, whatever the type is, this character won't be used to fill the gaps. For the case when d > 0:

  • If type is "usual" then the character is allowed to fill the gaps unlimited number of times.

  • If type is "scrabble" then the character is allowed to fill the gaps no more than d times.

  • If type is "anagram" then the character should be used exactly d times.

words

vector of words to search within. By default is set to words.eng.

See Also

scrabble, anagram

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
## Search 4-letter words starting with "c".
find_word("c.{3}")
## Disallow "a" and "b".
find_word("c.{3}", ban = "ab")
## Allow only "a" and "b" to fill the gap.
find_word("c.{3}", allow = "ab")
## Allow "a", "b", and "c", but then ban "c"
## result is the same as in the previous example
find_word("c.{3}", allow = "abc", ban = "c")

## Find no more than 4-letter words that have "th" bigram
library(magrittr)
find_word(".{0,4}") %>% find_word("*th*", words = .)
## count words that start with "th"
sum(find_word_l("th*"))
length(find_word("th*"))

## Find words that can be constructed of the "thing" word's letters.
find_word(allow = "thing", type = "scrabble")
## Get at lest 4-letter words.
find_word(".{4,}", allow = "thing", type = "scrabble")

## Find anagrams of the word "thing"
find_word(allow = "thing", type = "anagram")

Example output

  [1] "caba" "cabs" "caca" "cade" "cadi" "cads" "cafe" "caff" "cage" "cagy"
 [11] "caid" "cain" "cake" "caky" "calf" "calk" "call" "calm" "calo" "calp"
 [21] "calx" "came" "cami" "camo" "camp" "cams" "cane" "cang" "cann" "cans"
 [31] "cant" "cany" "capa" "cape" "caph" "capi" "capo" "caps" "carb" "card"
 [41] "care" "cark" "carl" "carn" "carp" "carr" "cars" "cart" "casa" "case"
 [51] "cash" "cask" "cast" "cate" "cats" "cauf" "cauk" "caul" "caum" "caup"
 [61] "cave" "cavy" "cawk" "caws" "cays" "ceas" "ceca" "cede" "cedi" "cees"
 [71] "ceil" "cell" "cels" "celt" "cens" "cent" "cepe" "ceps" "cere" "cero"
 [81] "cert" "cess" "cete" "chad" "chai" "chal" "cham" "chao" "chap" "char"
 [91] "chas" "chat" "chaw" "chay" "chef" "cher" "chew" "chez" "chia" "chic"
[101] "chid" "chik" "chin" "chip" "chis" "chit" "chiv" "chiz" "choc" "chon"
[111] "chop" "chou" "chow" "chub" "chug" "chum" "chut" "ciao" "cids" "ciel"
[121] "cigs" "cill" "cine" "cion" "cire" "cirl" "cist" "cite" "cito" "cits"
[131] "city" "cive" "civs" "clad" "clag" "clam" "clan" "clap" "clat" "claw"
[141] "clay" "clef" "cleg" "clem" "clew" "clip" "clit" "clod" "clog" "clon"
[151] "clop" "clot" "clou" "clow" "cloy" "club" "clue" "coal" "coat" "coax"
[161] "cobb" "cobs" "coca" "cock" "coco" "coda" "code" "cods" "coed" "coff"
[171] "coft" "cogs" "coho" "coif" "coil" "coin" "coir" "coit" "coke" "coky"
[181] "cola" "cold" "cole" "coll" "cols" "colt" "coly" "coma" "comb" "come"
[191] "comp" "coms" "cond" "cone" "coni" "conk" "conn" "cons" "cony" "coof"
[201] "cook" "cool" "coom" "coon" "coop" "coos" "coot" "cope" "cops" "copy"
[211] "cord" "core" "corf" "cork" "corm" "corn" "cors" "cory" "cose" "cosh"
[221] "coss" "cost" "cosy" "cote" "coth" "cots" "cott" "coup" "cour" "cove"
[231] "cowl" "cowp" "cows" "cowy" "coxa" "coxy" "coys" "coze" "cozy" "crab"
[241] "crag" "cram" "cran" "crap" "craw" "cred" "cree" "crew" "crib" "crim"
[251] "cris" "crit" "croc" "crop" "crow" "crud" "crus" "crux" "cube" "cubs"
[261] "cuds" "cued" "cues" "cuff" "cuif" "cuit" "cuke" "cull" "culm" "cult"
[271] "cums" "cunt" "cups" "curb" "curd" "cure" "curf" "curl" "curn" "curr"
[281] "curs" "curt" "cush" "cusk" "cusp" "cuss" "cute" "cuts" "cwms" "cyan"
[291] "cyma" "cyme" "cyst" "czar"
  [1] "cede" "cedi" "cees" "ceil" "cell" "cels" "celt" "cens" "cent" "cepe"
 [11] "ceps" "cere" "cero" "cert" "cess" "cete" "chef" "cher" "chew" "chez"
 [21] "chic" "chid" "chik" "chin" "chip" "chis" "chit" "chiv" "chiz" "choc"
 [31] "chon" "chop" "chou" "chow" "chug" "chum" "chut" "cids" "ciel" "cigs"
 [41] "cill" "cine" "cion" "cire" "cirl" "cist" "cite" "cito" "cits" "city"
 [51] "cive" "civs" "clef" "cleg" "clem" "clew" "clip" "clit" "clod" "clog"
 [61] "clon" "clop" "clot" "clou" "clow" "cloy" "clue" "cock" "coco" "code"
 [71] "cods" "coed" "coff" "coft" "cogs" "coho" "coif" "coil" "coin" "coir"
 [81] "coit" "coke" "coky" "cold" "cole" "coll" "cols" "colt" "coly" "come"
 [91] "comp" "coms" "cond" "cone" "coni" "conk" "conn" "cons" "cony" "coof"
[101] "cook" "cool" "coom" "coon" "coop" "coos" "coot" "cope" "cops" "copy"
[111] "cord" "core" "corf" "cork" "corm" "corn" "cors" "cory" "cose" "cosh"
[121] "coss" "cost" "cosy" "cote" "coth" "cots" "cott" "coup" "cour" "cove"
[131] "cowl" "cowp" "cows" "cowy" "coxy" "coys" "coze" "cozy" "cred" "cree"
[141] "crew" "crim" "cris" "crit" "croc" "crop" "crow" "crud" "crus" "crux"
[151] "cuds" "cued" "cues" "cuff" "cuif" "cuit" "cuke" "cull" "culm" "cult"
[161] "cums" "cunt" "cups" "curd" "cure" "curf" "curl" "curn" "curr" "curs"
[171] "curt" "cush" "cusk" "cusp" "cuss" "cute" "cuts" "cwms" "cyme" "cyst"
[1] "caba"
[1] "caba"
 [1] "bath" "beth" "both" "coth" "doth" "eath" "eth"  "ethe" "eths" "gath"
[11] "goth" "hath" "heth" "kith" "lath" "lith" "loth" "math" "meth" "moth"
[21] "myth" "nth"  "oath" "path" "pith" "rath" "ruth" "sith" "soth" "tath"
[31] "teth" "thae" "than" "thar" "that" "thaw" "the"  "thee" "them" "then"
[41] "thew" "they" "thig" "thin" "thio" "thir" "this" "tho"  "thon" "thou"
[51] "thro" "thru" "thud" "thug" "thus" "thy"  "with"
[1] 1859
[1] 1859
 [1] "ghi"   "gi"    "gin"   "git"   "hi"    "hin"   "hing"  "hint"  "hit"  
[10] "in"    "it"    "nigh"  "night" "nit"   "nth"   "thig"  "thin"  "thing"
[19] "ti"    "tig"   "tin"   "ting" 
[1] "hing"  "hint"  "nigh"  "night" "thig"  "thin"  "thing" "ting" 
[1] "night" "thing"

wfindr documentation built on May 2, 2019, 12:20 p.m.