Vscode-r: Send code from .R file to R Console

Created on 3 Oct 2017  Â·  7Comments  Â·  Source: Ikuyadeu/vscode-R

Is there any way to create a keybinding run code from a .R file without invoking the system commands? Specifically looking for a way to run code similarly to ESS in Emacs, using C-j and C-c (where the first C in both cases is the Ctrl key) to send a line and chunk (paragraph), respectively. Could this be added into the extension?

question

All 7 comments

@robertamezquita Thank you for issue.
I will fix Readme.

It is two solution.

  • If you have Mac ⌘+Shift+S
  • Click Second from the left button in this figure
    screen shot 2017-10-03 at 13 05 13

Okay, I found the way to run a line (just like RStudio, its Cmd + Enter, and the run source utility is useful. However, I'm wondering about running just individual code chunks, e.g.

```{r}

code_chunk <- function(x) {
cat("I am a chunk")
}

code_chunk_2 <- x %>%
mutate(...) %>%
transmute(...)
`` If I play my cursor at the beginning of line 1 with the firstcode_chunk, and enterC-c(akaCtrl+c, or some other shortcut, say to run a region, likeCtrl+r) then it would run all three lines at once (the whole chunk), and not runcode_chunk_2`, and if this could be done without necessarily highlighting the chunk prior to running the code.

Just wondering if you might have some insight on how this could be done, or alternately if this could be implemented in an update?

@robertamezquita Thank you for your suggestion.
And, I opened new issue in #27.
It's looks difficult and need more time, but I'll try to implement in future.

@robertamezquita I've added chunk detection for blocks #31. I'm going to get some feedback, but after I've confirmed it's not bogging the extension, I'll move on to pipes and multi-line functions. Any other "chunk" types you can think of?

The only other one I can think of is ggplot2 calls that use the +
operator, but besides that, I think those are the main ones!

On Mon, Oct 30, 2017 at 8:00 AM, Thomas Brittain notifications@github.com
wrote:

@robertamezquita https://github.com/robertamezquita I've added chunk
detection for blocks #31 https://github.com/Ikuyadeu/vscode-R/pull/31.
I'm going to get some feedback, but after I've confirmed it's not bogging
the extension, I'll move on to pipes and multi-line functions. Any other
"chunk" types you can think of?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Ikuyadeu/vscode-R/issues/26#issuecomment-340423783,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACU2LQnc_jxtpr6K9_n1BPGvJCRYLFqaks5sxbp6gaJpZM4PrjFR
.

--
Robert A. Amezquita
HHMI Gilliam Fellow | Blavatnik Associate
PhD Candidate | Kleinstein & Kaech Labs
Yale University | Department of Immunobiology
300 George St, Suite 505
New Haven, CT 06511-6663
Mobile: 858-245-3350
Email: robert.[email protected]

I became curious about how RStudio determines what editor text to send to the console when the user hits CTRL-ENTER, so I did some experimenting in RStudio 3.4.4.

Pipes etc.

It seems that there are many characters that RStudio will treat as 'continuing the line'. Copying the text below to the RStudio editor pane, placing the cursor on the second line, and hitting CTRL-ENTER will send both lines to the console pane.

1 +
  2

This also works if you replace + with:

  • Any of the following characters (possibly not exhaustive): !"$^&*-=:'~|/?
  • Anything between two % characters, encompassing pipes such as %>%

Brackets and nesting

The comments in the code below show what lines will be sent to the console pane when you put the cursor on that line in the editor pane and hit CTRL-ENTER. (This is a nonsense piece of code purely to show different combinations of brackets and nesting.)

if (TRUE) {              #  1. Sends lines 1-17
                         #  2. Sends lines 2-4
  a = data.frame(x = 2,  #  3. "
    y = 3)               #  4. "
  print(                 #  5. Sends lines 5-15
    a[                   #  6. "
      if (TRUE) {        #  7. Sends lines 7-13
        {                #  8. Sends lines 8-12
          (              #  9. Sends lines 9-11
            1            # 10. "
          )              # 11. "
        }                # 12. Sends lines 8-12
      }                  # 13. Sends lines 5-15
      ]                  # 14. "
  )                      # 15. " 
                         # 16. Sends lines 16-17, producing error
}                        # 17. Sends lines 1-17

I think RStudio's rule is that it sends the lines from the largest enclosing () or [] containing the current line (or the next code line if the current line is empty), WITHIN the smallest enclosing {}.

All that said, I don't think it's necessary to follow RStudio's approach exactly. For example, CTRL-ENTER on line 6 sending lines 6-14 rather than 5-15 also seems reasonable.

@Ladvien What's your status on this issue? If you're too busy at the moment, I'm happy to have a go at trying to implement RStudio-style rules.

@andycraig go for it. I’m a bit swamped at my job, so if I get to it, it won’t be soon.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JimmyZJX picture JimmyZJX  Â·  3Comments

tdeenes picture tdeenes  Â·  5Comments

Nightwingg picture Nightwingg  Â·  6Comments

michaelHL picture michaelHL  Â·  3Comments

awellis picture awellis  Â·  5Comments