posit-dev / positron

Positron, a next-generation data science IDE
Other
2.57k stars 79 forks source link

R: Add Run Line/Selection in Console to Toolbar menu, right click menu, command palette #2084

Closed jgutman closed 1 month ago

jgutman commented 9 months ago

We've just made these changes on the Python side, and I think may want similar changes in the R extension. So we currently have the keyboard shortcut (Cmd+Enter) to run a line/selection of R code in the console, but there's no other way to access it. This is in contrast to sourcing an entire R file, for which we have a keyboard shortcut, and it can also be accessed in the following places:

this button

image

this menu option (right click on file in editor)

image

command palette

image

In #2068 for Python, we added "Run Line/Selection in Console" as an option in all these places. For the Run/Play icon in the toolbar, we made Run Line/Selection the first/default option, so if you just click on the play icon, by default it just runs selection, or you could click on the dropdown and choose to source the entire file (second option in the list, below Run Line/Selection) image

I'm still undecided as to whether sourcing the entire file vs run line/selection should be the first/default option -- in RStudio we have two separate buttons (with slightly different icons), and maybe that's what we decide we want for Positron too. Either way I do think we should add this command in those three places for now, as it increases the discoverability of the keyboard shortcut.

juliasilge commented 3 months ago

Just got a request for this feature for R.

jonvanausdeln commented 1 month ago

Just tried on 2024.09.0-17 on Windows 11, but I only see run selection, I don't see the additional options, such as "Source R File". Note for the context menu, it doesn't matter if I have a line of code selected or not.. the only option available is "Run Selection in Console"

image

jmcphers commented 1 month ago

@jonvanausdeln Are you in an R package? The Source R File command was removed for R packages. Discussion in https://github.com/posit-dev/positron/pull/4567

jonvanausdeln commented 1 month ago

@jmcphers That seems to be somewhat of the issue. I had the repo qa-example-content opened. This in itself is not an R Package, but does have an R package directory inside of it.

This is a unique situation, that I doubt a normal user would encounter. Not sure if we should worry about it at the moment..

juliasilge commented 1 month ago

It is an R package, because of the DESCRIPTION at the root. If you open the subfolder as a workspace, you will see "Source R File" as an option.

jonvanausdeln commented 1 month ago

Verified Fixed

Positron Version(s) : 2024.09.0-17 OS Version(s) : Windows 11, MacOS 14

Test scenario(s)

Run selection now appears on all 3 places

Link(s) to TestRail test cases run or created:

jennybc commented 1 month ago

It is likely that this DESCRIPTION file should specify the Type field, so that the qa-example-content project itself is not mistaken for a package (even though some of the workspaces it contains are):

https://github.com/posit-dev/qa-example-content/blob/main/DESCRIPTION

"Package" is really the main official Type, so you just need to make sure you put anything other than "Package" here. Apparently "Frontend" is also recognized and means something. I think we should put something like ... "TestAssets"? I'm not sure what the constraints are, if any, e.g. around characters or whitespace.

Anecdotally on GitHub I see a smattering of "Book", "Shiny", "Compendium", "Website", etc. for people using DESCRIPTION in non-package projects.


Relevant R package detection code in positron-r:

https://github.com/posit-dev/positron/blob/df4656b46ca4675e8c58d1cad9c8b1a29303264b/extensions/positron-r/src/contexts.ts#L19-L22

Official documentation around the Type field:

https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Package-types-1