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

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."

Related

Quarto equivalent to "exclude:" YAML command in distill

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.

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 include an external file in a Moodle question with R/exams?

In order to include statistical tables when using R-exams, I know that one can just use the option pages inside the function exams2nops(). But when using exams2moodle() how should one proceed?
In Moodle one can upload a file within a question and add a link to the embedded file. Is it possible to do it through R exams?
You can easily include various kinds of supplementary files in R/exams and then export them to Moodle or other learning management systems. Two steps need to be taken:
While processing the .Rmd or .Rnw exercise the supplementary file(s) need to be created in the current working directory (which is a temporary directory by default). This can either be done be creating the file via some R code or by copying an existing file. The convenience function include_supplement() simplifies this.
The supplementary file then needs to be included as a link in the question text. In .Rmd this would be something like [myfile.pdf](myfile.pdf) and in .Rnw exercises \url{myfile.pdf}.
An example for such an inclusion is the lm exercise template shipped along with the package, see: http://www.R-exams.org/templates/lm/. This exercise creates a .csv file on the fly within R and then includes it.
An example for the include_supplement() function is available in the Rlogo exercise template that copies the R logo image from the R system and then includes it in the exercise. See: http://www.R-exams.org/templates/Rlogo/.
Final comment: For a distribution table it would also be possible to include this directly as an HTML table in Moodle. For example, you could generate suitable Markdown or LaTeX code within the R code of the exercise.

docfx Shared Content between Markdown Files

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.

Missing index.html and folders structure?

After using bookdown::render_book("index.Rmd", "bookdown::gitbook") in RStudio/Windows the index file is not being generated. As the first chapter is #preface (in "index.rmd"), the file being generated is preface.html. The consequence is that it is not working in GitHub. Am I missing something?
How should be the settings in yaml files in order to keep the .rmd (source files of the book) in a subfolder of my R projects and generate the book in another folder? I am trying to have the bookdowm integrated in my research folder structure.
Thanks for this amazing package!!!
For the first question, my problem is that I had written two chapters in the index file. After removing the "# About the author" part, the index.html file came back.

Resources