When using R
code chunks in an .Rnw
document, the emacs buffer automatically detects that the cursor is within a code chunk (i.e. within <<>>
and @
), and switches to ESS-mode -- this is very valuable because one can get ESS-based code-formatting within the code-chunk, and more-usefully, one can send code lines/regions to the inferior *R*
process-buffer.
How do I get the same functionality in an org-mode file within R
code blocks (i.e. between #+begin_src R
and #+end_src
) -- I'd like emacs to automatically recognize it's within an R code code block, and turn on ESS-mode so I can send snippets of code to the *R*
process. I am aware that I can do Ctl-C '
and switch to a different ESS-mode buffer where I can edit the code and get all the other ESS-mode conveniences (including sending code to R
). However I'd like to not have to do this, i.e. I want to be able to send code-snippets from the R code block in the same org-mode buffer.
AFAIK, this can not be done with the current implementation of Org-mode.
I'm not sure this is doable at all within Org-mode without some delving into elisp code. The main point of the C-c '
command in Org-mode is so that you have an additional buffer that has all the syntax highlighting that you want/need for your particular language.
There is probably a way to hack around this for R
-specific code by writing some Org-mode hook that checks first to see if you are in an #+begin_src R
...#+end_src R
block, and then checking for a code chunk. I suspect this would be messy and conflict with other Org-mode features. In addition, you would have to write another function to grab the current code block and pass it to Org-mode's R
interpreter, along with all the options you added to the src
block.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With