GithubHelp home page GithubHelp logo

rstudio / bookdown Goto Github PK

View Code? Open in Web Editor NEW
3.6K 123.0 1.3K 18.38 MB

Authoring Books and Technical Documents with R Markdown

Home Page: https://pkgs.rstudio.com/bookdown/

License: GNU General Public License v3.0

R 22.53% HTML 1.89% TeX 7.11% CSS 7.56% Makefile 0.02% Lua 0.86% JavaScript 60.03%
bookdown book gitbook latex html epub rmarkdown

bookdown's Introduction

bookdown

R-CMD-check CRAN release Codecov test coverage

A open-source (GPL-3) R package to facilitate writing books and long-form articles/reports with R Markdown. Features include:

  • Generate printer-ready books and ebooks from R Markdown documents
  • A markup language easier to learn than LaTeX, and to write elements such as section headers, lists, quotes, figures, tables, and citations
  • Multiple choices of output formats: PDF, LaTeX, HTML, EPUB, and Word.
  • Possibility of including dynamic graphics and interactive applications (HTML widgets and Shiny apps)
  • Support for languages other than R, including C/C++, Python, and SQL, etc.
  • LaTeX equations, theorems, and proofs work for all output formats
  • Can be published to GitHub, bookdown.org, and any web servers
  • Integrated with the RStudio IDE
  • One-click publishing to https://bookdown.org

Book

bookdown: Authoring Books and Technical Documents with R Markdown

Installation

You can install the package from CRAN as follows:

install.packages("bookdown")

If you want to use the development version of the bookdown package, you can install the package from GitHub via the pak package:

# install.packages("pak")
pak::pak('rstudio/bookdown')

Usage

The easiest way to start a new Bookdown project is from within RStudio IDE. Go to File > New Project > New Directory > Book project using bookdown.

This will create a new directory with an example book as template. You can build the HTML version of this example book without doing any modification:

  • Go into the Build Pane in the RStudio IDE
  • Click on Build Book > bookdown::gitbook

You can also run bookdown::render_book() in the R console.

Learn more about using bookdown in the Getting started section.

Getting help

There are two main places to get help:

  1. The RStudio community is a friendly place to ask any questions about bookdown. Be sure to use the bookdown tag.

  2. Stack Overflow is a great source of answers to common bookdown questions. Use the tags [r][bookdown] if you ask a question.

Code of Conduct

Please note that the bookdown project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

bookdown's People

Contributors

adamvi avatar apreshill avatar atusy avatar cderv avatar daattali avatar dataopt avatar dshuman1 avatar ellisvalentiner avatar hadley avatar haozhu233 avatar jjallaire avatar jtbayly avatar jtr13 avatar krlmlr avatar maelle avatar njbart avatar noamross avatar petehaitch avatar prdm0 avatar rblades avatar rlesur avatar rstub avatar salim-b avatar shenfei avatar shirdekel avatar shuliyey avatar thierryo avatar triceraflops avatar weebeasties avatar yihui avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bookdown's Issues

Is `\@ref` syntax only exclusive to `bookdown` at the moment?

I've enjoyed the \@ref feature for referencing tables and figures. I noticed, however, that this seems exclusive to bookdown. Is that the case?

Is there anyway to have this same referencing syntax across any .Rmd? I would love to use it in a .Rmd I'm currently writing with output: html_document!

Apologies as I know that this is not exactly an issue with bookdown but more of a request to have this feature extended to any rmarkdown document.

Issues with bookdown gitbook Travis build

I recently setup a gh-pages hosted bookdown gitbook (https://github.com/nate-d-olson/mgmgnotes) and ran into a few issues, which I expected since the package is under active development. I was able to find work arounds for the issues and the Travis-CI build is working. Here is a list of the issues I ran into along with my work arounds.

  • Documentation related
    • File numbering- section/ subsection and role of _bookdown.yml, it is unclear from the documentation how the file numbering and rmd list in _bookdown.yml determine chapters.
    • The Travis build required a DESCRIPTION file, also needed to state devtools was a dependency for installing packages on github e.g. bookdown. Travis build log with error https://travis-ci.org/nate-d-olson/mgmgnotes/builds/116715029
  • Running scripts build and deploy scripts - needed to add the following to the .travis.yml due to a permissions issue. Not sure if it is better to define this in the .travis.yml or change permissions locally. Travis build log https://travis-ci.org/nate-d-olson/mgmgnotes/builds/116736240
before_script:
 - chmod +x ./_build.sh
 - chmod +x ./_deploy.sh
  • Issues with _deploy.sh pushing to github (see build error message below ). I fix the issue I added git config --global user.email and git config --global user.name to the deploy script. I might have not set the GH_TOKEN up correctly though. Travis build log https://travis-ci.org/nate-d-olson/mgmgnotes/builds/116739556
$ ./_deploy.sh
Cloning into 'book-output'...
remote: Counting objects: 175, done.
remote: Compressing objects: 100% (118/118), done.
remote: Total 175 (delta 62), reused 152 (delta 44), pack-reused 0
Receiving objects: 100% (175/175), 457.89 KiB | 0 bytes/s, done.
Resolving deltas: 100% (62/62), done.
Checking connectivity... done.
*** Please tell me who you are.
Run
  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: empty ident name (for <travis@testing-worker-linux-docker-18f5f0e1-3374-linux-14.prod.travis-ci.org>) not allowed

Function to clear caches?

It would be nice to have a function that could inspect _bookdown.yml and figure out all files that need to be deleted if you want to start completely from fresh.

Before_chapter_script doesn't work?

In _bookdown.yaml I have:

before_chapter_script: "_common.R"

and in _common.R I have:

knitr::opts_chunk$set(
  comment = "#>",
  collapse = TRUE,
  cache = TRUE
)

but the chunk options don't seem to have any affect. What am I missing?

render before publish?

In the docs for publish_book I say "be sure to render all your formats before publishing". Should we just automatically render before publishing? (perhaps with a render argument to override this behavior). I guess if books are computationally expensive it would be annoying to have them auto-rendered but in that case perhaps caching is in use.

Don't have a strong opinion here, just wanted to raise the issue for discussion.

Equivalent of oldbookdown::screenshot()

I don't think we have anything that's quite equivalent yet. There are two important differences from knitr::include_graphics():

  • you can use it inside r for inline graphics
  • it preserves the original size of the image (using optional dpi argument to scale) (i.e. it ignores fig.width and fig.height)

This is most useful for diagrams (so the screenshot() name isn't great), where you have carefully sized the image.

Can not copy files

bookdown::render_book("index.rmd")

#>  Error in file.copy(files_md[!rerun], basename(files_md[!rerun]), overwrite = TRUE) : 
#>   file can not be copied both 'from' and 'to' 
#> 4 stop("file can not be copied both 'from' and 'to'") 
#> 3 file.copy(files_md[!rerun], basename(files_md[!rerun]), overwrite = TRUE) at render.R#138
#> 2 render_new_session(files, main, force_knit, output_format, clean, 
#>     envir, ...) at render.R#94
#> 1 bookdown::render_book("index.rmd") 

Any ideas?

Title Documents

I'm guessing there's a way to do this with custom templates somehow, but it would be nice if there were a simple way to add a title to a document. This would be prepended on PDFs and perhaps integrated into the <title> of HTML?

Allow duplicate chunk labels?

After merging all Rmd files, there might be duplicate chunk labels (e.g. the current ggplot2 book has this problem), we can allow such labels by setting a knitr option, but it may make the automatic figure/table labels unpredictable, e.g. a chunk with label foo may get \label{fig:foo-1} when the label is duplicated and knitr has automatically "corrected" it.

Should output_dir default to book?

This just seems like such a natural way to work to me, that I wonder if it shouldn't be the default. It seems fundamentally different to working on a single file - it feels more like preparing a website to publish, so like jekyll etc, it should default to putting all the files in a new directory.

html_dependency problem

bookdown::render_book("index.rmd")
#> Error: path for html_dependency not found: /tmp/RtmpO4fv0m/widgetbindingcb3263a9aa9f 

traceback()
#> 10: stop("path for html_dependency not found: ", list$src$file, call. = FALSE) at html_dependencies.R#141
#> 9: FUN(X[[i]], ...) at html_dependencies.R#128
#> 8: lapply(dependencies, validate_html_dependency) at html_dependencies.R#93
#> 7: dependency_resolver(all_dependencies) at html_extras.R#13
#> 6: html_extras_for_document(knit_meta, runtime, dependency_resolver, 
#>   format_deps) at html_document_base.R#92
#> 5: base(...) at output_format.R#81
#> 4: output_format$pre_processor(yaml_front_matter, utf8_input, runtime, 
#>   knit_meta, files_dir, output_dir) at render.R#387
#> 3: rmarkdown::render(main, output_format, ..., clean = clean, envir = envir, 
#>   run_pandoc = TRUE, knit_meta = knit_meta) at render.R#129
#> 2: render_new_session(files, main, force_knit, output_format, clean, 
#>   envir, ...) at render.R#86
#> 1: bookdown::render_book("index.rmd")

Any ideas?

Navigation is not working in the preview of a book

When I preview the a book using the preview addin, or serve_book() the navigation doesn't work in the RStudio Viewer. When opened from the viewer into an external browser links are downloaded as html files, and not opened in the browser. If I open index.html for the same book directly in an external browser navigation works correctly.

When I open index.html of the book directly withservr::httw and servr::httd they show the same behaviour: links in the TOC are downloaded and not opened in the browser. The same index.html TOC works correctly when opened directly in an external browser.

Output format for single documents?

Is there an output document tailored for individual chapters? It's nice to be able to use the same cache and visual appearance while iterating on a single chapter.

Gitbook: add "edit me" link

That links back to github. This probably doesn't need to be built into the gitbook style, but there should be sufficient customisation ability that I can add it (maybe there already is but I don't know about it)

Cross-Reference Section by Title

Currently, I can use @\ref{} to add a reference to a section, which will insert the numerical ID of the section. I'd prefer, in some cases, to have the link contain the section title (which may, of course, be different from the bookmark title). e.g.

You'll find more information in the '@\ref(somesect)' section.

## Something Here {#somesect}

My hope is that that would render as:

You'll find more information in the 'Something Here' section.

Maybe that requires an extra argument a la @\ref(somesect, title=TRUE). Even if I had to manually provide the text for the link, that would be a feasible work-around for now.

Object 'arry' not found in parse_fig_labels

Looks like a variable got missed in a recent refactor.

> bookdown::render_book('', bookdown::html_chapters())


processing file: _main.Rmd

  |                                                                       
  |                                                                 |   0%
  |                                                                       
  |.................................................................| 100%
  ordinary text without R code


output file: _main.knit.md

/usr/local/bin/pandoc +RTS -K512m -RTS _main.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output _main.html --smart --email-obfuscation none --standalone --section-divs --table-of-contents --toc-depth 3 --template /usr/local/lib/R/site-library/bookdown/templates/default.html --number-sections --variable 'theme:bootstrap' --include-in-header /tmp/Rtmp6s3ilB/rmarkdown-str1606b35cffc.html --mathjax --highlight-style pygments --variable navigationjs=libs/navigation 
Error in parse_fig_labels(content) : object 'arry' not found
Calls: <Anonymous> ... split_chapters -> resolve_refs_html -> parse_fig_labels
Execution halted

Cmd + Shift + K loses place in html preview

Not exactly sure where this issue belongs but if you have:

---
knit: bookdown::preview_chapter

---

Then pressing Cmd + Shift + K always takes you to the top of the rendered document. This is obviously frustrating when you're working further down the chapter.

cc @jjallaire @jmcphers

Make render_book() work?

By looking for _bookdown.yml in current directory, and adding document format metadata to it as well.

Turning a book into an R package

Are there any plans on automatically turning a book into an R package? Using travis, I've already specified a DESCRIPTION file with all my dependencies. Without thinking, I've added datasets to a data directory.

In order to make this a package I would:

  • Move *.Rmd to inst/vignettes (this could easily be scripted)
  • Any scripts to R/
  • Perhaps tweak the DESCRIPTION file.

The "book" can then be installed and viewed as a vignette.

Self-contained format

When I create a self-contained HTML and remove the _book folder or move it to another directory, the content is ok, but the layout is strange with two scrollbars:

2016-03-24 08_24_40-rstudio

--- 
title: "Authoring A Book with R Markdown"
date: "`r Sys.Date()`"
author: "Dieter Menne"
knit: "bookdown::render_book"
output:
  bookdown::gitbook: 
    self_contained: true

---

# Index

yml:

book_filename: "dieter-bookdown.Rmd"
chapter_name: "Chapter "
rmd_files: [ "index.Rmd", "c.Rmd", "b.Rmd", "a.Rmd" ]

Set output directory

We run the following to compile HTML and PDF outputs

R -e "setwd('/data');" \
   -e "bookdown::render_book('', bookdown::html_chapters(lib_dir='out/assets'), output_dir='out');"
   -e "bookdown::render_book('', 'bookdown::pdf_book', output_file='out/_main.pdf', output_dir='out')"

the hope is that all output files would be rendered in ./out. It took some finagling to get that to work for both HTML and PDF, but it seems like the above set of options successfully executes. The issue is that the chapters HTML is still in the current directory, along with a slew of _main* files.

It would be great to have a way to avoid polluting the source tree and instead keep all rendered docs in a separate dir.

gitbook: allow user scaling

Currently have:

<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

I think

<meta name="viewport" content="width=device-width, initial-scale=1">

Is more appropriate, because it's often useful to zoom into pictures etc.

Problem with knit and merge

When I set new_session:yes in bookdown.yml I get:

bookdown::render_book("index.rmd")
Error in (function (input, output_format = NULL, output_file = NULL, output_dir = NULL,  : 
  unused argument (run_pandoc = FALSE)
Calls: local ... eval -> eval -> eval -> eval -> do.call -> <Anonymous>
Execution halted

Does this suggest I have an out of date dependency?

default HTML output on iPad

Hi @yihui
When browsing the standard HTML output from bookdown on an iPad, there doesn't seem to be a way to collapse the sidebar containing the table of contents. So, when reading the bookdown or r4ds websites, the sidebar always takes up over 1/3 of the reading space on the iPad. It would be great if the default HTML output allowed one to collapse/expand the TOC, or to see TOC in a menu.

Thanks
Kyle

Include build tip in docs

Create a _build.sh that contains:

#!/usr/bin/env Rscript
bookdown::render_book("index.rmd")

Then chmod +x _build.sh

Then In RStudio, you can map Cmd + Shift + B to build the complete book by going to project options, build tools, select custom and then selecting _build.sh.

@jjallaire will this always get you the version of R that's running in RSudio?

Next button has confusing click target

On safari (at least), if I hover over anywhere over the next button, my mouse pointer turns into the "clicky hand", but clicking does nothing. It's only if I'm over the text that clicking works to take me to the next page

Cross-referencing syntax

I just converted a large report from rmarkdown with css figure/caption numbering (rstudio/rmarkdown#522) to bookdown::html_document2. This worked nicely; great feature.

I am not so happy about the latex-lookalike syntax for cross-referencing. Since more than 3 year, there has been an inofficial standard in pandoc which needs some clumsy postprocessing, but worked once you got the setup done:

https://github.com/lierdakil/pandoc-crossref

Malformed remote specification when installing

I'm quite exited about the bookdown project and want to try it out and provide feedback. However, if I try to install bookdown either by cloning and installing the repository and or by running

devtools::install_github("rstudio/bookdown")

I get the error message

Installing bookdown
Error: Malformed remote specification 'rstudio/rmarkdown'

Installing the github version of rstudio/rmarkdown doesn't really fix it. Is there anything I can do to get it up and running?

Appendix

For LaTeX output, inserting \appendix is basically all we need to do. For HTML, there is no concept of "appendix", so we need some sort of hack to mark certain sections after a certain point to be appendices. (Requested by @aronatkins)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.