posit-dev / positron

Positron, a next-generation data science IDE
Other
1.17k stars 31 forks source link

Cmd + shift + k does not knit an R Markdown document #3737

Open JosiahParry opened 3 days ago

JosiahParry commented 3 days ago

Positron Version:

Positron Version: 2024.06.1 (Universal) build 27 Code - OSS Version: 1.90.0 Commit: https://github.com/posit-dev/positron/commit/a893e5b282612ccb2200102957ac38d3c14e5196 Date: 2024-06-26T02:08:06.673Z Electron: 29.4.0 Chromium: 122.0.6261.156 Node.js: 20.9.0 V8: 12.2.281.27-electron.0 OS: Darwin arm64 23.4.0

Steps to reproduce the issue:

  1. Create an Rmd file
  2. hover over the play button to assert that the keyboard shortcut should be available
image
  1. Press keyboard shortcut to try rendering Rmd
  2. assert that nothing happens

What did you expect to happen?

The document would render.

Additional thoughts on this:

I find this behavior to be really awkward and I think the story can be improved greatly if Positron and quarto extension didn't classify Rmd files as Quarto language type.

image

If Rmd is recognized for an Rmd document you can create keybindings that utilize something like

       "args": {
            "langId": "rmd",
            "code": "rmarkdown::render(...)"
        }

Forcing Rmd to be quarto makes everything uncomfortable.

alearrigo commented 2 days ago

When I try to render a .Rmd file with "Render Document with R Markdown" I get:

> rmarkdown::render("/Users/alessandroarrigo/Documents/GitHub/Osservatorio/R/Analisi/Markdown/Bollettino_ISS.Rmd")
Error: pandoc version 1.12.3 or higher is required and was not found (see the help page ?rmarkdown::pandoc_available).
Execution halted

 *  The terminal process "/bin/zsh '-l', '-c', '/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/bin/R -e 'rmarkdown::render("/Users/alessandroarrigo/Documents/GitHub/Osservatorio/R/Analisi/Markdown/Bollettino_ISS.Rmd")''" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

but pandoc is installed:

rmarkdown::find_pandoc()
$version
[1] ‘3.1.12.3’

$dir
[1] "/Applications/Positron.app/Contents/Resources/app/bin/pandoc"

If I try with command+shift+k / Preview it works almost as expected. I say almost because the rmd has a YAML with:

output: 
  word_document:
    reference_docx: Boll_ISS_temp.docx
    fig_caption: yes

and the preview doesn't automatically read the output option and it renders the document as HTML. In RStudio it works great but I tried in VSCode and it has the same behaviour, so I don't think is positron fault but maybe the workflow may be different somehow.

JosiahParry commented 2 days ago

@alearrigo this is because the document is rendered using quarto which has different options. For example it doesn't recognize output and instead wants format.

You can work around this by using quarto but then that isn't actually a solution. Instead it is using an alternative tool

juliasilge commented 1 day ago

@alearrigo Can you open a separate issue with your problem? If you use the command "Render Document with R Markdown", it renders using R Markdown and not Quarto FYI. Seems like there is some problem with pandoc version.

juliasilge commented 1 day ago

@JosiahParry We have some tension around that particular keyboard shortcut. I recommend that you set up your own user-level keyboard shortcut like this:

    {
        "key": "cmd+shift+k",
        "command": "r.rmarkdownRender",
        "description": "Render .Rmd",
        "when": "resourceExtname == '.Rmd' && editorTextFocus",
    }