Instantly share code, notes, and snippets.

Embed
What would you like to do?
A quick rewrite of Shaun Jackman's original `make` lesson, written for Rich Fitzjohn's `remake`
make_plot <- function(mydata){
qplot(Length, Freq, data=mydata)
}
packages:
- ggplot2
- rmarkdown
sources:
- functions.R
targets:
all:
depends:
- report.html
words.txt:
command: file.copy(from = "/usr/share/dict/words", to = target_name)
words:
command: readLines("words.txt")
Length:
command: nchar(words)
hist_dat:
command: table(Length)
hist_df:
command: as.data.frame(hist_dat)
histogram.png:
command: make_plot(hist_df)
plot: true
report.md:
knitr: true
depends:
- histogram.png
- hist_df
report.html:
command: render("report.md")
title author date output
English Word lengths
Jenny Bryan
`r format(Sys.time(), '%d %B, %Y')`
html_document
keep_md
true

On most *nix systems, the file /usr/share/dict/words contains a bunch of words. On my machine, it contains r sum(hist_df$Freq) words.

I computed the length of each word, i.e. the number of characters, and tabulated how many words consist of 1 character, 2 characters, etc.

The most frequent word length is r with(hist_df, Length[which.max(Freq)]).

Here is a histogram of word lengths.

Fig. 1 A histogram of English word lengths

@aammd

This comment has been minimized.

Show comment
Hide comment
@aammd

aammd Nov 12, 2015

Yiou can get a handy diagram with remake::diagram(); that might be the most useful thing for teaching.

rplot

Owner

aammd commented Nov 12, 2015

Yiou can get a handy diagram with remake::diagram(); that might be the most useful thing for teaching.

rplot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment