I'm currently writing something in R Markdown. Whenever I Knit the document, RStudio's preview takes me back to the very beginning of the document. Is there a way to make this new preview display a location closer to where I've been working by default? For example, can I make it preview at a location near where my cursor for typing is?
The comments have suggested a number of workarounds. So far, my best is to just type the section number of the section where I'm working in to the search bar that RStudio's preview window provides. I'd click on the relevant entry in the table of contents, but I use output: github_document: toc: true number_sections: true
, which is waiting on a patch to its numbered tables of contents.
There are two ways to render an R Markdown document into its final output format. If you are using RStudio, then the “Knit” button (Ctrl+Shift+K) will render the document and display a preview of it.
R Markdown is an extension of the markdown syntax. R Markdown files are plain text files that typically have the file extension . Rmd . They are written using an extension of markdown syntax that enables R code to be embedded in them in a way which can later be executed.
rmarkdown will preserve the text, code results, and formatting contained in your original . Rmd file. Conversion lets you do your original work in markdown, which is very easy to use. You can include R code to knit, and you can share your document in a variety of formats.
Not quite as simple as you had in mind, but it is possible to use javascript to control what section of an html document is displayed:
---
title: "Untitled"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
```{js}
location.hash = "#goto";
```
```{r, results='asis'}
cat(sprintf("# %s\n\nSection text here.\n\n", 1:10), sep = "")
```
# GOTO
Scroll Here
```{r, results='asis'}
cat(sprintf("# %s\n\nSection text here.\n\n", 11:20), sep = "")
```
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With