positron icon indicating copy to clipboard operation
positron copied to clipboard

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

Open JosiahParry opened this issue 1 year ago • 6 comments

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.

JosiahParry avatar Jun 29 '24 16:06 JosiahParry

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.

alearrigo avatar Jun 30 '24 10:06 alearrigo

@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

JosiahParry avatar Jun 30 '24 12:06 JosiahParry

@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 avatar Jul 01 '24 15:07 juliasilge

@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",
    }

juliasilge avatar Jul 01 '24 17:07 juliasilge

Let's consider adding this keybinding to the RStudio Keymap, just for .Rmd. (This will only render but not preview in the way that an RStudio user may be expecting.)

juliasilge avatar Jul 05 '24 17:07 juliasilge

"We have some tension around that particular keyboard shortcut"

Is there another situation where when the current file has .Rmd that another keybinding should be used? To me it feels odd that this keybinding should be relegated to the RStudio settings. Comparing this to VS Code there is only a system keybinding whose When would not conflict with an .Rmd file extension.

image

The only other conflict would be with the Quarto extension. Using the R extension with Quarto in VS Code behaves as one would expect:

  • {rmarkdown} used when an R Markdown file is present
  • quarto render/preview used when a Quarto file is present

JosiahParry avatar Jul 05 '24 17:07 JosiahParry