Questions tagged [knitr-spin]

`knitr::spin` is a tool for formatting specially marked R script into a beautiful document that contains comments, plots, tables and code. Use together with the generic `knitr` tag to guide search for spinr related questions.

knitr::spin is a part of the knitr package by Yihui Xie intended for dynamic generation of documents complete with computation results and code directly out of R scripts.

Useful links

26 questions
8
votes
2 answers

Can knitr::spin() pick up global options?

knitr::spin() is a great tool for those that prefer to write code first and text second. I would like to use it to produce documents with little code echoing, but lots of output and text comments. However, every time that I turn off echoing and then…
Mark Payne
  • 557
  • 5
  • 12
5
votes
2 answers

Generating a table of contents (toc) when using knitr's spin()

I use knitr's spin() function to generate html reports. Is there a way to make spin() generate a table of contents (toc) for headings embedded in the comments somehow? (Note: I cannot use pandoc for that and have to use the markdown & html generator…
lith
  • 929
  • 8
  • 23
3
votes
2 answers

Using R, RStudio Knit to PDF, how to pass tilde to prevent line wrapping "Table~\ref{table:data-from-phone}"?

In Latex, it is common to reference a label using the "~" to keep the number attached to the label such as Figure or Table. https://tex.stackexchange.com/questions/227285/problems-with-tilde-and-line-breaking/227296 shows an example of this. A fully…
mshaffer
  • 959
  • 1
  • 9
  • 19
3
votes
1 answer

R knitr: use spin() with R and Python code

With the advent of reticulate, combining R and Python in a single .Rmd document has become increasingly popular among the R community (myself included). Now, my personal workflow usually starts with an R script and, at some point, I create a…
fdetsch
  • 5,239
  • 3
  • 30
  • 58
3
votes
1 answer

DT::datatables() generated html table shows display anomalies (missing characters) when column level search is used

I am trying to put interactive, sortable tables in html summaries produced by using rmarkdown::render from an R script. For producing tables I am using datatables() from DT package. Reports are generated fine and tables look pretty good, until you…
ktyagi
  • 975
  • 10
  • 15
2
votes
2 answers

Is there a global command line knit option as eval=FALSE for all chunks?

I quite often make mistakes in the text part of *.Rmd documents and, in some cases, fixing and running knit() implies re-running R commands that can take a while. Therefore, it is an advantage running the .Rmd document without actually executing the…
user2955884
  • 405
  • 2
  • 11
2
votes
2 answers

Include R script with markdown tags as external file in Rmarkdown file

suppose I have an .R file tmp.R with markdown tags, e.g. #' # header 5+1 and I want to include that into a (much larger) .Rmd file as external source. R code and markdown tags shall be evaluated as if it were rendered directly. How I would do…
Tom
  • 934
  • 12
  • 20
2
votes
1 answer

How to pass a parameter when rendering an R script with spin?

I'm creating an HTML output from a .R script with the command rmarkdown::render(input = "my_script.R"). It calls knitr::spin() and successfully produces an HTML output. In that .R file, there is a filtering variable school_level whose value I want…
Sam Firke
  • 21,571
  • 9
  • 87
  • 105
2
votes
0 answers

knitr: how to specify different fig.paths for PNGs and SVGs

As you will see in the minimal example below, I use knitr::spin() with global option dev=c('png','svg'). The reason is that I want the PNG in the report rather than the SVG, as I am worried that the latter will make my browser slow (my plots often…
Felix
  • 51
  • 2
2
votes
1 answer

Adding titles inside loop/function of knitr spin script

I have an r script that I'd like to use to generate an HTML report using knitr spin. Much of the code that runs is within loops/functions. How can I generate titles within the document for content that is created within those functions/loops? I…
jrdnmdhl
  • 1,935
  • 18
  • 26
1
vote
2 answers

Using R, RStudio Knit to HTML, how to include "inline" an external HTML document chunk?

The Definitive guide speaks of adding HTML fragments to other documents https://bookdown.org/yihui/rmarkdown/html-document.html#html-fragments It also speaks of "includes" as advanced customization…
mshaffer
  • 959
  • 1
  • 9
  • 19
1
vote
0 answers

Code folding for multiple languages in bookdown

I was able to put successfully in practice the solution presented by @SébastienRochette at this StacOverflow post, to add show/hide buttons to R, Python and Bash code blocks in bookdown books. it works great and also allows you to customize the…
f0nzie
  • 1,086
  • 14
  • 17
1
vote
2 answers

How to edit a markdown code block using org-edit-special in emacs

I am would like to edit my R chunks from RMarkdown files the way org-edit-special does. I found generic-edit-special from jonathan leech-pepin that does a similar thing for js, css and ruby in html files. I figured I could tweak it as suggested by…
Gallarus
  • 476
  • 3
  • 9
1
vote
1 answer

How to handle encodings in knitr spin_child

Following recommendations on https://yihui.name/en/2018/11/biggest-regret-knitr, I started saving my .R files with UTF-8 encoding (using RStudios "Save with encoding"). Seems to work well, until it comes to using spin_child. Under Windows, for…
Henrik
  • 65
  • 4
1
vote
1 answer

Running Code Chunks in R (knitr package)

I'm working on a markdown file I was sent that wants some of the script to be written in code chunks using the knitr package, which I've never used before. The problem I'm running into is that the scripts don't appear to be working when placed in…
user6855566
1
2