posit-dev / positron

Positron, a next-generation data science IDE
Other
1.98k stars 60 forks source link

Rendering with RMarkdown "knit" option in YAML header #3910

Open ncbss opened 3 weeks ago

ncbss commented 3 weeks ago

In RStudio, I have the code below in the YAML header to customize the output file location and its name, e.g., add a date a specific name to the PDF output. I noticed that this doesn't seem to work for Positron. Would there be a different of achieving the same?

knit: (function(inputFile, encoding) { rmarkdown::render(inputFile, encoding = encoding, output_file = paste('../output/Main Analysis_', format(Sys.Date(),'%Y%m%d'),'.pdf', sep='')) })

Thank you

juliasilge commented 3 weeks ago

Can you share an example .Rmd file that uses code like this, so we can have more detail about your workflow?

ncbss commented 3 weeks ago

Hi there, Yes, please see attached. I am sending as .txt because GitHub won't let me attach an .rmd file.

test.txt

Thanks.

juliasilge commented 2 weeks ago

Ah yep, we don't currently have support for using this specialized knit hook in Positron. I will say that AFAIK this is undocumented behavior for RStudio and that will have to influence how this gets prioritized. 😬

Here is a smaller example for us to use later:

---
title: "A wonderful R Markdown document"
knit: (function(inputFile, encoding) { rmarkdown::render(inputFile, encoding = encoding, output_file = paste('my-beautiful-file-', format(Sys.Date(),'%Y%m%d'),'.html', sep='')) })
output:
  html_document:
    math_method: katex
---

```{r echo = FALSE}
knitr::opts_chunk$set(echo = TRUE)

R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

Here is some math:

$1 + 1$

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars) 

Including Plots

You can also embed plots, for example:

plot(pressure)

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.