Skip to content

Instantly share code, notes, and snippets.

@aammd aammd/functions.r
Created Nov 12, 2015

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: "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.
![*Fig. 1* A histogram of English word lengths](histogram.png)
@aammd

This comment has been minimized.

Copy link
Owner Author

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
You can’t perform that action at this time.