-
Notifications
You must be signed in to change notification settings - Fork 3
/
README.Rmd
213 lines (140 loc) · 4.32 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
---
output: github_document
editor_options:
chunk_output_type: console
---
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "##",
fig.path = "README-"
)
```
```{r, include=FALSE}
options("width"=110)
tmp <- packageDescription( basename(getwd()) )
```
```{r, results='asis', echo=FALSE}
cat("#", tmp$Title)
```
```{r, include=FALSE}
filelist.R <- list.files("R", recursive = TRUE, pattern="\\.R$", ignore.case = TRUE, full.names = TRUE)
filelist.tests <- list.files("tests", recursive = TRUE, pattern="\\.R$", ignore.case = TRUE, full.names = TRUE)
filelist.cpp <- list.files("src", recursive = TRUE, pattern="\\.cpp$", ignore.case = TRUE, full.names = TRUE)
lines.R <- unlist(lapply(filelist.R, readLines))
lines.tests <- unlist(lapply(filelist.tests, readLines))
lines.cpp <- unlist(lapply(filelist.cpp, readLines))
length.R <- length(grep("(^\\s*$)|(^\\s*#)|(^\\s*//)", lines.R, value = TRUE, invert = TRUE))
length.tests <- length(grep("(^\\s*$)|(^\\s*#)|(^\\s*//)", lines.tests, value = TRUE, invert = TRUE))
length.cpp <- length(grep("(^\\s*$)|(^\\s*#)|(^\\s*//)", lines.cpp, value = TRUE, invert = TRUE))
```
**Status**
<a href="https://travis-ci.org/petermeissner/crossword.r">
<img src="https://api.travis-ci.org/petermeissner/crossword.r.svg?branch=master">
<a/>
<a href="https://cran.r-project.org/package=crossword.r">
<img src="http://www.r-pkg.org/badges/version/crossword.r">
</a>
<a href="https://codecov.io/gh/petermeissner/crossword.r/branch/master">
<img src="https://codecov.io/gh/petermeissner/crossword.r/branch/master/graph/badge.svg">
</a>
<a href="https://r-pkg.org/maint/[email protected]">
<img src="http://cranlogs.r-pkg.org/badges/grand-total/crossword.r">
</a>
<a href="https://r-pkg.org/maint/[email protected]">
<img src="http://cranlogs.r-pkg.org/badges/crossword.r">
</a>
*lines of R code:* `r length.R`, *lines of test code:* `r length.tests`
**Youtube video of Hamburg UseR Meetup presentation**
https://youtu.be/56qrwa4bzK8
**Development version**
```{r, include=FALSE}
source_files <-
grep(
"/R/|/src/|/tests/",
list.files(recursive = TRUE, full.names = TRUE),
value = TRUE
)
last_change <-
as.character(
format(max(file.info(source_files)$mtime), tz="UTC")
)
```
```{r, results='asis', echo=FALSE}
cat(tmp$Version)
cat(" - ")
cat(stringr::str_replace(last_change, " ", " / "))
```
**Description**
```{r, results='asis', echo=FALSE}
cat(tmp$Description)
```
**License**
```{r, results='asis', echo=FALSE}
cat(tmp$License, "<br>")
cat(tmp$Author)
```
**Citation**
```{r, results='asis', eval=FALSE}
citation("crossword.r")
```
**BibTex for citing**
```{r, eval=FALSE}
toBibtex(citation("crossword.r"))
```
**Installation**
Stable version from CRAN:
```{r, eval=FALSE}
install.packages("crossword.r")
```
Latest development version from Github:
```{r, eval=FALSE}
devtools::install_github("petermeissner/crossword.r")
```
**Help wanted**
- word-clue lists to accompany the package (like the one used throughout the examples below)
- grid placement algorithm improvements
* make denser grids,
* allow for space between non-overlapping words (https://github.com/petermeissner/crossword.r/issues/8),
* allow for alternative algorithms,
* make it faster,
* make it auto-optimize
- make more exports
* PDF (see https://github.com/petermeissner/crossword.r/tree/master/rendering for some first tests, also: https://github.com/petermeissner/crossword.r/issues/7)
* HTML/JS (see https://github.com/petermeissner/crossword.js)
# Usage
```{r, message=FALSE}
# load the library
library(crossword.r)
# set seed for pseudo random number generator
set.seed(123)
# create a new 4 by 4 crossword
cw <- Crossword$new(rows = 10, columns = 10)
cw_words <- cw_wordlist_animal_en[sample(nrow(cw_wordlist_animal_en)),]
cw$add_words(
words = cw_words$words,
clues = cw_words$clues
)
```
```{r}
# use the default print method to have a look
cw
```
```{r}
# access to letters on the grid
cw$letters
# access to words placed on the grid, their co-ordinates and so on
cw$words
```
```{r}
# get some statistics
cw$density()
```
```{r, results=FALSE}
# export to JSON
cw$to_json(pretty=TRUE)
```
```{r, echo=FALSE}
# export to JSON
cat(paste(substring(cw$to_json(pretty=TRUE),1,765), "}\n\n[...]"))
```