Quarto equivalent to "exclude:" YAML command in distill - r

In R, I am moving a distill website to quarto website. In distill, I can prevent all the Rmd documents in a directory called "internal" from being knitted by adding this to the _site.yml
exclude:
- internal
The same trick does not work in quarto. Is there a quarto equivalent, somehow to indicate which directories should be excluded during the knitting/rendering process?

Thanks to C Wickham for answering the question:
Yes, you can control which documents are knitted by specifying the render targets. Two options that might work for you are:
Renaming internal/ to _internal/, and relying on the automatic ignoring of files and directories with a prefix of _.
Explicitly, specifying that files in internal/ should not be rendered in _quarto.yml, e.g. (edited from example in docs linked above):
project:
render:
- "*.qmd"
- "!internal/"
The "*.qmd" is necessary to describe which files should be rendered, so if you've got some .Rmd files as well, you might need to add another line with "*.Rmd" to make sure they are rendered.

Related

R / Bookdown: specify rmd_files in render_book() function

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
]

Rmarkdown Links - How to get the name of the current file without extension?

I am creating a bookdown document in which I provide a link for people to download the PDF, DOCX and TEX outputs of the current section they are looking at.
All output documents are in a folder named "Compilation" and have the same name of the original Rmd documents they were retrieved.
For exemple, I have the file "1.2-Endowment-effect.Rmd" in which I coded:
Download Links: [[PDF]](./Compilation/1.2-Endowment-effect.pdf)
[[DOCX]](./Compilation/1.2-Endowment-effect.docx)
[[TEX]](./Compilation/1.2-Endowment-effect.tex)
I wanted to know if, instead of writting "1.2-Endowment-effect" in the code, there would be a way to take the name of the current Rmd file and add the extension. Something like:
Download Links: [[PDF]](./Compilation/NameCurrentFile.pdf)
[[DOCX]](./Compilation/NameCurrentFile.docx)
[[TEX]](./Compilation/NameCurrentFile.tex)
I have to repeat that process for lots of Rmd files, and I want to avoid always updating the links.
Thank you for your help.
The output filenames can be generated with inline R expressions, e.g.,
Download Links: [PDF](./Compilation/`r xfun::with_ext(knitr::current_input(), 'pdf'`)
Please read the help pages of the functions xfun::with_ext() and knitr::current_input() if you are not familiar with them.
To include this part in all other Rmd documents, you can put the content in a child document named, say, _download.Rmd, and in your main Rmd documents, use
```{r, child='_download.Rmd'}
```

How to render documents in sub-directories with rmarkdown::render_site()?

For example I have a markdown file called index.md in the root folder and another markdown file in a subfolder called docs/tools/git.md. When I run render_site(), index.html is generated from index.md, but no document is generated from docs/tools/git.md.
The help page of rmardown::render_site says:
R Markdown (.Rmd) and plain markdown (.md) files in the root directory are rendered.
I have tried to add include: ["docs/tools/git.md"] to the _site.yml but this doesn't help.
This question is related, but I already know how to work with sub directories in knitr.
What I want to know is how to render documents in sub-directories with rmarkdown::render_site()?
It is not possible to have sub-directories with rmardown::render_site() according to the author Yihui Xie who referred to the Rmarkdown website page of the bookdown documentation in a comment above:
"Before blogdown was invented, there was actually a relatively simple way to render websites using rmarkdown. The structure of the website has to be a flat directory of Rmd files (no subdirectories for Rmd files) and a configuration file in which you can specify a navigation bar for all your pages and output format options."
It goes on to specify that these simple sites are still useful in some cases. The first two points:
"You are familiar with generating single-page HTML output from R Markdown, and all you want is to extend this to generating multiple pages from multiple Rmd files."
"It suffices to use a flat directory of Rmd files. You do not write a blog or need RSS feeds."

slidify lectureSite: workflow and customizations

I am getting started with http://slidify.github.io/lectureSite/. I like the idea and the template very much. However, being new to this, I am struggling with customization.
Let me first explain what this 'lectureSite' architecture offers. The main code is based on rmarkdown and slidify and the customizations of the layout are mainly controlled in css files. The 'lectureSite' consists of an html webpage that serves as a contents page and starting point to access different slides ('lectures'), much of it created automagically. It looks as great as it sounds!
Each lecture is stored in a separate directory with its own 'assets' directory. So in a course made of 10 lectures, one has 10 directories, each with its own css and js. However, to achieve a common style for the whole course, one would like most of the customizations to be shared among all the lectures. My main problem is how to deal with this.
Question: How should I deal with the css customizations that I would like to share among all the lectures?
I have been successful in customizing each lecture by inserting the css code into each rmarkdown file between <style> and </style> tags, but now I would like to take the customizations to a place where they may be shared. I expected that by including a slidify.css file inside assets/css the styles would be picked up, but they are not: could I be doing something wrong or was my expectation incorrect to begin with? And besides, there are so many of those assets/css directories that it would be tedious to have to copy the css into each every time it is modified. Is there a mechanism to set a single css file that would override the css inside assets/css?
I also tried to make a 'declaration' at the top of the rmarkdown file (something I saw there: http://rmarkdown.rstudio.com/html_document_format.html) with:
css : slidify.css
but that gave the following error message:
pandoc: Could not fetch slidify.css
slidify.css: openBinaryFile: does not exist (No such file or directory)
Error: pandoc document conversion failed with error 67
Execution halted
An alternative would be to source() a text file with the customization between <style> and </style> tags. Are there any disadvantages to this approach? And btw what is the code for sourcing an external file from rmarkdown?
Consider the following structure:
assets -> put custom img/js/css/layout assets
lectures -> folder containing lectures
Lecture 01
Lecture 02
Lecture 03
libraries -> frameworks, highlighters and widgets
index.Rmd -> Rmd source for home page
site.yml -> Site related configuration
and suppose you are inside one of the Lectures index.Rmd files. I found the following seems to 'by-pass' the local assets directory to source the 'root' directory instead:
url : {lib: "../../libraries", assets: "../../assets"}
If you place your css files into "../../assets/css/custom.css", that is the 'master' assets directory at the top of the structure (at the root, to say it differently), then it will be sourced by slidify. I deleted all the other assets directories and didn't find it did any harm (all they contained to begin with was one single file ribbons.css). Not extensively tested, but it worked on Firefox and Chrome.
In this way, I can have a single customization css for all the chapters.
However, this structure appears to work only for the html5slides framework and not for io2012. For io2012 I explain here what I did (it worked for me, but I have no idea if it's the right way):
https://github.com/ramnathv/slidify/issues/409
Somewhat more involved. Hopefully future versions of slidify will make it easier. One problem with dumping style files into the root assets directory is that, with the html5slides framework, all files are sourced. So my idea of having framework-specific css files in the assets directory doesn't work, because the styles are all sourced and some overwrite one another. So keeping the custom css files in framework-specific directories is probably a better approach anyhow.
I also found the following way of sharing R customizations and knit opts (or whatever they're called)
```{r 'preamble', message = FALSE, warning = FALSE, error = FALSE, echo = FALSE, tidy = FALSE, comment = NA, cache = FALSE} # probably several redundant ones in there
require(knitr)
opts_chunk$set(echo = FALSE, cache = FALSE) # example of knit options
source('../../shared/shared.R') # here I share common R code
```

knitr: Document does not change anymore

I have a .Rnw document in which I include childs. The childs produce tables via the 'latex' command of the Hmisc library in R.
When I make changes in the child documents, these changes do not anymore change the pdf document. My first guess was to use the chunk option 'eval=TRUE', but this does not change anything. Then, I saw, that the tables are actually saved to a .tex file with same name as the .Rnw document. I deleted this file and after compilation with knitr I got an error:
Error: Latexmk: Could not find file documentname.tex.
I assume, this is not the way to do it. Now I am out of ideas what to do. I appreciate some help on my problem.
Best
Simon
Allright, when trying to construct a simple example, I actually found out, that neither the packages I included nor the nesting of child documents interfere with the compilation via knitr. The reason was a simple error in the low-level .Rnw document, where a Hmisc latex table had a label, that missed a closing speech mark.
This causes then the output pdf not to change - I assume, that in this case the already constructed .tex file is included instead of letting knitr recompile the .Rnw documents and this hasn't changed since the last compilation?
What I wonder about is the different format of the landscape ctable in the document. Using a simple knitr document just with \documentclass{article} produces well placed tables. In my document using a template for the JFE, I get a table that extends over the whole page and even in footnotesize it is far away from the great appearance in the simple document. There is only a margin of less than half a cm on the right and the left. Page size is the same: both US letter... Can I probably control that via knitr or only via resizebox?

Resources