Created
November 12, 2015 20:32
-
-
Save aammd/72a5b98356893c001001 to your computer and use it in GitHub Desktop.
A quick rewrite of Shaun Jackman's original `make` lesson, written for Rich Fitzjohn's `remake`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
make_plot <- function(mydata){ | |
qplot(Length, Freq, data=mydata) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "English Word lengths" | |
author: "Jenny Bryan" | |
date: "`r format(Sys.time(), '%d %B, %Y')`" | |
output: | |
html_document: | |
keep_md: yes | |
--- | |
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. | |
 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yiou can get a handy diagram with
remake::diagram()
; that might be the most useful thing for teaching.