commit 851a88941113423471e126aedab6a01688ed76d8 Author: hadley Date: Mon Jul 27 16:52:19 2015 -0500 First commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f745d15 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +*.pdf +.Rproj.user +.Rhistory +_cache +_site +cache +diamonds.csv +temp.Rmd +*.html +*_cache +*_files +figures \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3621fb5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,29 @@ +language: c + +before_install: + - curl -OL http://raw.github.com/craigcitro/r-travis/master/scripts/travis-tool.sh + - chmod 755 ./travis-tool.sh + - ./travis-tool.sh bootstrap + +install: + # Install binary pandoc from Rstudio + - export PATH="$HOME/pandoc:$PATH" + - mkdir $HOME/pandoc + - curl -O https://s3.amazonaws.com/rstudio-buildtools/pandoc-1.12.3.zip + - unzip -j pandoc-1.12.3.zip pandoc-1.12.3/linux/debian/x86_64/pandoc + -d $HOME/pandoc + - chmod +x $HOME/pandoc/pandoc + - pandoc --version + + # Install jekyll + - travis_retry gem install jekyll mime-types + + # Install R packages + - ./travis-tool.sh r_binary_install knitr png + - ./travis-tool.sh r_install ggplot2 dplyr tidyr + - ./travis-tool.sh github_package hadley/bookdown + +script: jekyll build + +after_success: + - cp -r figures/ _site/figures diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3c7d796 --- /dev/null +++ b/LICENSE @@ -0,0 +1 @@ +This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivs 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/3.0/us/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. diff --git a/README.md b/README.md new file mode 100644 index 0000000..63049d3 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# R packages + +This is code and text behind the [R for data science](http://r4ds.had.co.nz) +book. + +The site is built using jekyll, with a custom plugin to render `.rmd` files with +knitr and pandoc. To create the site, you need: + +* jekyll gem: `gem install jekyll` +* bookdown: `install_github("hadley/bookdown")` +* [pandoc](http://johnmacfarlane.net/pandoc/) +* [knitr](http://yihui.name/knitr/): `install.packages("knitr")` diff --git a/_config.yml b/_config.yml new file mode 100644 index 0000000..180b609 --- /dev/null +++ b/_config.yml @@ -0,0 +1,5 @@ +name: R packages +markdown: redcarpet +highlighter: pygments + +exclude: ["CONTRIBUTING.md", "README.md", "book"] diff --git a/_plugins/knit.r b/_plugins/knit.r new file mode 100755 index 0000000..0d0f1ce --- /dev/null +++ b/_plugins/knit.r @@ -0,0 +1,24 @@ +#!/usr/bin/Rscript +library(rmarkdown) +library(bookdown) +library(methods) + +args <- commandArgs(trailingOnly = TRUE) +path <- args[1] + +if (!file.exists(path)) { + stop("Can't find path ", path, call. = FALSE) +} + +if (file.access(path, 4) != 0) { + stop("Can't read path ", path, call. = FALSE) +} + +html_path <- render(path, html_chapter(raw = TRUE, toc = "toc.rds"), + quiet = TRUE) + +read_file <- function(path) { + size <- file.info(path)$size + readChar(path, size, useBytes = TRUE) +} +cat(read_file(html_path)) diff --git a/_plugins/rmarkdown.rb b/_plugins/rmarkdown.rb new file mode 100644 index 0000000..0bc0451 --- /dev/null +++ b/_plugins/rmarkdown.rb @@ -0,0 +1,33 @@ +require 'tempfile' + +module Jekyll + class RMarkdownConverter < Converter + safe :false + priority :high + + def matches(ext) + ext =~ /^\.(rmd|rmarkdown)$/i + end + + def output_ext(ext) + ".html" + end + + def convert(content) + f = File.new("temp.Rmd", "w") + f.write(content) + f.write("\n") + f.flush + + # http://rubyquicktips.com/post/5862861056/execute-shell-commands + content = `_plugins/knit.r temp.Rmd` + + if $?.exitstatus != 0 + raise "Knitting failed" + end + + content + # File.unlink f.path + end + end +end \ No newline at end of file diff --git a/contribute.rmd b/contribute.rmd new file mode 100644 index 0000000..14891f1 --- /dev/null +++ b/contribute.rmd @@ -0,0 +1,28 @@ +--- +title: Contributing +layout: default +--- + +# Contributing + +This book has been developed in the open, and it wouldn't be nearly as good +without your contributions. There are a number of ways you can help make the +book even better: + +* If you don't understand something, please + [let me know](mailto:h.wickham@gmail.com). Your feedback on what is confusing + or hard to understand is valuable. + +* If you spot a typo, feel free to edit the underlying page and send a pull + request. If you've never done this before, the process is very easy: + + * Click the edit this page on the sidebar. + + * Make the changes using github's in-page editor and save. + + * Submit a pull request and include a brief description of your changes. + "Fixing typos" is perfectly adequate. + + * If you make significant changes, include the phrase "I assign the + copyright of this contribution to Hadley Wickham" - I need this so I can + publish the printed book. diff --git a/cover.png b/cover.png new file mode 100644 index 0000000..4244458 Binary files /dev/null and b/cover.png differ diff --git a/index.rmd b/index.rmd new file mode 100644 index 0000000..73c104e --- /dev/null +++ b/index.rmd @@ -0,0 +1,17 @@ +--- +layout: default +title: Welcome +output: bookdown::html_chapter +--- + +# R for Data Science + +This is the book site for __"R for data science"__. It will be published with O'Reilly in July 2016. + +Cover image + + + + diff --git a/r4ds.Rproj b/r4ds.Rproj new file mode 100644 index 0000000..4f10a56 --- /dev/null +++ b/r4ds.Rproj @@ -0,0 +1,16 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: XeLaTeX + +AutoAppendNewline: Yes +StripTrailingWhitespace: Yes