crosswordio

{crosswordio} is a package for reading/writing crossword puzzles in PUZ format.

What’s in the box

Installation

You can install the latest development version from GitHub with:

# install.package('remotes')
remotes::install_github('coolbutuseless/crosswordio')

Pre-built source/binary versions can also be installed from R-universe

install.packages('crosswordio', repos = c('https://coolbutuseless.r-universe.dev', 'https://cloud.r-project.org'))

Read and plot a crossword puzzle in PUZ format

puz <- read_puz(system.file("sample.puz", package = "crosswordio"))
puz$grid
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
#>  [1,] "S"  "A"  "L"  "V"  "A"  "G"  "E"  "."  "J"  "A"   "C"   "K"   "P"  
#>  [2,] "H"  "."  "E"  "."  "M"  "."  "X"  "."  "E"  "."   "O"   "."   "R"  
#>  [3,] "O"  "N"  "T"  "H"  "E"  "B"  "A"  "L"  "L"  "."   "M"   "A"   "O"  
#>  [4,] "R"  "."  "Y"  "."  "T"  "."  "M"  "."  "L"  "."   "E"   "."   "F"  
#>  [5,] "T"  "R"  "O"  "P"  "H"  "Y"  "."  "E"  "Y"  "E"   "T"   "E"   "E"  
#>  [6,] "C"  "."  "U"  "."  "Y"  "."  "A"  "."  "B"  "."   "O"   "."   "S"  
#>  [7,] "U"  "N"  "R"  "E"  "S"  "E"  "R"  "V"  "E"  "D"   "."   "."   "S"  
#>  [8,] "T"  "."  "H"  "."  "T"  "."  "R"  "."  "A"  "."   "C"   "."   "I"  
#>  [9,] "S"  "E"  "A"  "."  "."  "R"  "O"  "U"  "N"  "D"   "A"   "B"   "O"  
#> [10,] "."  "."  "I"  "."  "C"  "."  "G"  "."  "S"  "."   "T"   "."   "N"  
#> [11,] "B"  "I"  "R"  "T"  "H"  "D"  "A"  "Y"  "."  "S"   "A"   "F"   "A"  
#> [12,] "L"  "."  "D"  "."  "E"  "."  "N"  "."  "P"  "."   "R"   "."   "L"  
#> [13,] "A"  "D"  "O"  "R"  "E"  "."  "T"  "A"  "L"  "K"   "A"   "T"   "I"  
#> [14,] "C"  "."  "W"  "."  "S"  "."  "L"  "."  "E"  "."   "C"   "."   "S"  
#> [15,] "K"  "E"  "N"  "N"  "E"  "D"  "Y"  "."  "A"  "T"   "T"   "I"   "M"  
#>       [,14] [,15]
#>  [1,] "O"   "T"  
#>  [2,] "."   "H"  
#>  [3,] "R"   "I"  
#>  [4,] "."   "G"  
#>  [5,] "T"   "H"  
#>  [6,] "."   "."  
#>  [7,] "E"   "W"  
#>  [8,] "."   "I"  
#>  [9,] "U"   "T"  
#> [10,] "."   "T"  
#> [11,] "R"   "I"  
#> [12,] "."   "N"  
#> [13,] "V"   "E"  
#> [14,] "."   "S"  
#> [15,] "E"   "S"
puz$across
#>  [1] "The raising of sunken or wrecked ships (7)"         
#>  [2] "Poker machine prize (7)"                            
#>  [3] "Alert and aware (2,3,4)"                            
#>  [4] "The Polynesian indigenous people of New Zealand (5)"
#>  [5] "Sporting prize (6)"                                 
#>  [6] "Canines, especially of the upper jaw (8)"           
#>  [7] "Not booked (10)"                                    
#>  [8] "Work with a needle (3)"                             
#>  [9] "Great mass of salt water (3)"                       
#> [10] "Circular road junction (10)"                        
#> [11] "Yearly anniversary (8)"                             
#> [12] "Animal viewing expedition (6)"                      
#> [13] "Love intensely (5)"                                 
#> [14] "Chatty (9)"                                         
#> [15] "35th US president (7)"                              
#> [16] "Occasionally (2,5)"
plot(puz, add_position = TRUE, cex = 1.4)

Create a puzzle and save in PUZ format

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# This grid is the "Sator Square"
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
grid <- matrix(c(
"S", "A", "T", "O", "R",
"A", "R", "E", "P", "O",
"T", "E", "N", "E", "T",
"O", "P", "E", "R", "A",
"R", "O", "T", "A", "S"
), 5, 5, byrow = TRUE)

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# In the Sator Square, all down and across words are identical
# and in Latin!
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
down <- across <- c(
  "sower, planter",
  "unknown word, perhaps a proper name of a non-Latin origin",
  "holds, keeps, comprehends, possesses, masters, preserves, sustains",
  "service, pains, labor; care, effort, attention",
  "wheels"
)

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Write crossword to a file in "puz" format
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
file <- tempfile()
write_puz(
  grid   = grid, 
  across = across, 
  down   = down, 
  title  = "SATOR SQUARE",
  file   = file
)

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Read the data back and plot it
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
puz <- read_puz(file)
plot(puz, scale = 30, cex = 0.7)

Resources