I cannot find out how to make a page break in R bookdown.
With page break I mean that the content within one page is displayed as one website.
By default there is always a page break in front of every new section (like # Chapter 1).
So, if I run render_book each section becomes one html file.
But, if I have a lot of subsections then these sites get very long.
I would like to have page breaks before every subsection (like ## Chapter 1.1).
So far I tried adding \newpage, \pagebreak, --------------- to the .Rmd or to just provide the .Rmd files in the same structure as I would like to have them as .html files.
Either way, the .html files are always created according to the sections.
I think this is specified by the split_by argument of gitbook as documented here.
Sounds like you are using chapter but you want to be using section
The split_by argument specifies how you want to split the HTML output
into multiple pages, and its possible values are:
rmd: use the base filenames of the input Rmd files to create the HTML filenames, e.g., generate chapter3.html for chapter3.Rmd;
none: do not split the HTML file (the book will be a single HTML file);
chapter: split the file by the first-level headers;
section: split the file by the second-level headers;
chapter+number and section+number: similar to chapter and section, but the files will be numbered;
Related
We use bookdown very frequently to write course material at our university. We use rmd_files: within "_bookdown.yaml" to specify the rmd-files to be included in the book. Our bookdown projects tend to become rather long and complex, and _bookdown.yamlends up looking something like this:
rmd_files:
- index.Rmd
- folder1/subfolder1/file1.Rmd
- folder1/subfolder1/file2.Rmd
- folder1/subfolder2/file3.Rmd
- folder2/subfolder3/file4.Rmd
...
Using _bookdown.yaml to specify the files is limiting in the following ways:
it leads to a lot of repetition (e.g. folder1 is repeated for each child element)
the complex structure is implicit and obscure
selecting only a subset of files to be rendered involves manual labour (say I just want to use all files from folder 1)
So we have moved over to depicting our file-structure in a separate yaml file and using helper functions to update _bookdown.yaml according to our needs. This method seems a bit clunky, and it would be much more elegant if we could pass a vector of files to render_book() instead of specifying the rmd-files in _bookdown.yaml. Is that possible?
Note: using render_book(..., preview = TRUE) is not a solution, we would like to re-render the book with a specific set of rmd-files.
Have you read the new Rmarkdown Cookbook
Here is cuts from the book
This WOULD match your directory IF you pull all your .RMDs from the child folders and in the same parent directory as the index.RMD.
If you name the files accordingly, then your book will render in the correct order (numerically). If you do this, you will not have to name every .RMD file in the yaml. You just have to render your index.RMD which gets instructions from the YAML you have saved
You should be able to include any files from anywhere, using this line in your _bookdown.yml (NB: brackets, commas, and indent!)
rmd_files: [
index.Rmd,
folder1/subfolder1/file1.Rmd,
folder1/subfolder1/file2.Rmd,
folder1/subfolder2/file3.Rmd,
older2/subfolder3/file4.Rmd
]
I have a workflow where I'm downloading Google Docs as docx, then processing them to markdown for export to other formats in the R environment.
When I convert to markdown with pandoc_convert, I get embedded images, but they're not linked.
I want to add link syntax similar to this post,
i.e. I want this (not linked):
![m'lady](https://i.imgur.com/v8IVDka.jpg)
to be (linked):
[![m'lady](https://i.imgur.com/v8IVDka.jpg)](https://i.imgur.com/v8IVDka.jpg)
for every image in a document. How to do?
After much toil, I put this function together, which solves my issue:
addLinksToPhotos<-function(mdfile){
d<-readLines(mdfile)
s<-sapply(d,function(x) {
replacementPattern="[\\1(\\2)](\\2)\\3"
gsub('.*?(?<firstpart>!\\[[^\\]]*?\\])\\((?<filename>.*)\\)(?<potentialHTML>\\{.*?\\})?.*?',x=x,replacement=replacementPattern,perl=T)
},USE.NAMES = F)
writeLines(s,mdfile)
}
#usage
addLinksToPhotos("myRMarkdownDoc.rmd")
It will read every line in the markdown file, looking for the photo ![]() pattern, including where it has style coding in braces ![](){}. It will modify each instance to have a linked image [![]()](){}.
I generate reports using rmarkdown::render() function on a list of .Rmd files and I get one HTML file for each of them.
That was fine until my dataset got bigger and my reports now contain >100 figures... The HTML files often end-up being >100MB and I now have some very big ones (~500MB).
The .Rmd is separated in several chunks so one might think I have to split my .Rmd in smaller files (let's say one chunk per file).
This is not (easily) doable because the .Rmd defines a data-processing workflow (figures generated in chunk3 require processings made in chunk1 and chunk2).
I would like to know if it is possible to split the rendering in several HTML files automatically.
Ideally I dream about a 'splitHeader' argument in render() that would generate separate HTML file for each header of a specified level.
I guess an ugly solution is to manually add conditional statements for every chunk/header that I would like rendered (or not), and call render() several time with different arguments. But this is extremely inefficient (and ugly, I said that already)...
Would somebody have suggestions to achieve that ?
I am not sure if this solve (or at least help to solve): You can have multiple independent .Rmd files (childs) dividing the content as you like. In a "Mother" file, you can add the child using:
```{r child = "yourChild.Rmd"}
```
The child .Rmd files should no contain any header information. That is, delete the first lines in you .Rmd that are something like:
---
title: "Your Title"
author: "Your name"
output: html_notebook
---
In DocFX, I have a block of content which i need to put on all (or most) markdown files. Is there a way to merge or pull the contents of another md file in to the current file? Basically i am trying not to repeat myself and looking for some sort of sharing mechanism.
You can do this with file inclusion which is part of the DocFX flavored markdown (DFM).
DFM adds syntax to include other file parts into current file, the
included file will also be considered as in DFM syntax.
Is it possible to include an image in documentation generated by roxygen? I have a number of functions that are essentially wrappers for ggplot() that I'd like to document by showing an example of the output.
As per the change list from the announcement of R 2.14:
Rd markup has a new \figure tag so that figures can be included in
help pages when converted to HTML or LaTeX. There are examples on
the help pages for par() and points().
From: http://cran.r-project.org/doc/manuals/R-exts.html#Figures
To include figures in help pages, use the \figure markup. There are three forms.
The two commonly used simple forms are \figure{filename} and \figure{filename}{alternate text}. This will include a copy of the figure in either HTML or LaTeX output. In text output, the alternate text will be displayed instead. (When the second argument is omitted, the filename will be used.) Both the filename and the alternate text will be parsed verbatim, and should not include special characters that are significant in HTML or LaTeX.
The expert form is \figure{filename}{options: string}. (The word ‘options:’ must be typed exactly as shown and followed by at least one space.) In this form, the string is copied into the HTML img tag as attributes following the src attribute, or into the second argument of the \Figure macro in LaTeX, which by default is used as options to an \includegraphics call. As it is unlikely that any single string would suffice for both display modes, the expert form would normally be wrapped in conditionals. It is up to the author to make sure that legal HTML/LaTeX is used. For example, to include a logo in both HTML (using the simple form) and LaTeX (using the expert form), the following could be used:
\if{html}{\figure{logo.jpg}{Our logo}}
\if{latex}{\figure{logo.jpg}{options: width=0.5in}}
The files containing the figures should be stored in the directory man/figures. Files with extensions .jpg, .pdf, .png and .svg from that directory will be copied to the help/figures directory at install time. (Figures in PDF format will not display in most HTML browsers, but might be the best choice in reference manuals.) Specify the filename relative to man/figures in the \figure directive.