This repository has been archived by the owner on Oct 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
171 lines (136 loc) · 3.37 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# zipfs
<!-- badges: start -->
<!-- badges: end -->
---
The zipfs pacakge contains functions to help fit Zipf's Law to book texts from the Gutenberg project.
## Installation
This package isn't on CRAN, but you can install it from GitHub with:
```{r, eval = FALSE}
# install.packages("remotes")
remotes::install_github("merely-useful/zipfs")
```
## Usage
```{r}
library(zipfs)
text <- c("Star light, star bright,
First star I see tonight;
I wish I may, I wish I might,
Have the wish I wish tonight.")
(word_freq <- count_words(text))
plot_rank(word_freq$n, add_fit = TRUE)
fit_zipfs(word_freq$n)
```
## Curated R History
This wouldn't be in the pacakge README, but trying to keep it around in case it is useful.
An attempt to keep track of the R code run on the Console in the act of creating the package.
### Add dracula data
```{r, eval = FALSE}
use_data_raw("dracula")
# Edit data-raw/dracula.R
# Source data-raw/dracula.R
devtools::load_all(".")
dracula # Check data available
use_r("dracula")
# Add data docs to R/dracula.R
devtools::document(".")
?dracula # Check docs
```
### Add book meta functions
```{r, eval = FALSE}
use_r("book-meta")
# Edit R/book-meta.R to add functions
use_package("tibble")
use_package("stringr")
use_pipe()
devtools::load_all(".")
extract_element("Author: Bram Stoker", "Author")
book_meta(dracula[1:20])
# Code -> Insert Roxygen Skeleton
# Edit Roxygen comment for `book_meta()`
devtools::document()
?book_meta
```
### Add `count_words()`
```{r, eval = FALSE}
use_r("count")
# Edit count.R
devtools::load_all(".")
count_words(dracula)
# Code -> Insert Roxygen Skeleton
# Edit Roxygen comment for `count_words()`
devtools::document()
?count_words
```
### Add license
```{r, eval = FALSE}
use_mit_license("Charlotte Wickham")
```
### Add plot function
```{r, eval = FALSE}
use_r("plot")
# Edit R/plot.R
devtools::load_all(".")
plot_rank(1:100)
# Insert ROcygen skeleton
# Edit roxygen comment for `plot_rank()`
devtools::document()
?rank
word_freqs <- count_words(dracula)
plot_rank(work_freqs$n)
```
### Add fit function
```{r, eval = FALSE}
use_r("fit")
# Edit R/fit.R
devtools::load_all(".")
word_freqs <- count_words(dracula)
fit_zipfs(word_freqs$n)
use_test()
# Edit tests/testthat/test-fit.R
devtools::test()
devtools::document()
# Edit Roxygen comment for `fit_zipfs()`
?fit_zipfs
```
### Update plot function to take `add_fit` argument
```{r, eval = FALSE}
use_r("plot") # quick way to open file
# Edit `plot_rank()` code and docs
devtools::load_all()
plot_rank(word_freqs$n, add_fit = TRUE)
?plot_rank
```
### More tests for `book_meta()`
```{r eval = FALSE}
use_test("book-meta")
# Edit tests, running expectation as I go
devtools::test()
use_r()
# Add input check to `book_meta()`
devtools::test()
```
### Getting pkgdown website
```{r, eval = FALSE}
usethis::use_pkgdown()
pkgdown::build_site()
# Preview and edit DESCRIPTION, README etc.
usethis::use_github_pages()
usethis::use_github_action("pkgdown")
# Commit and Push
# Push failed, had to Pull to get gh-pages branch?
# In dev version of usethis, this replaces all of above
# and adds links in useful places
usethis::use_pkgdown_github_pages()
```