Vim-R-plugin icon indicating copy to clipboard operation
Vim-R-plugin copied to clipboard

Add support for alternative engines when executing a single chunk

Open khughitt opened this issue 11 years ago • 3 comments

Would it be possible to add support for executing individual bash, etc. chunks?

Currently, when \ce is used, all chunks are treated as R code. I'm not sure how feasible it would be, but it would be nice also be able to support executing individual chunks written in other languages.

khughitt avatar Sep 17 '14 15:09 khughitt

The plugin is intended to be an R plugin, and it works by sending code to R Console. To send code to other interpreter, we would have to start the interpreter (in an Tmux panel or in an external terminal) before sending the code. I'm sorry, but I'm not going to implement this feature.

Currently, you can do something like:

system("/path/to/shell_script.sh")
system("/path/to/python_script.py")

You can also run the plugin as a global plugin (please, see :h r-plugin-global).

Finally, you or someone else can write the code to do what you want and source it (please, see :h vimrplugin_source).

jalvesaq avatar Sep 17 '14 18:09 jalvesaq

That sounds reasonable. I tend to use knitr/rmarkdown a lot recently, so I sometimes forget that you are using source not just calling knit under the hood.

Currently, it looks like for the "send chunk up to here" (\ch) function, you generate a temporary file with all of the code up to that point.

Since, executing knit has a similar effect of loading executing in a running console, do you think it might work to use knit instead of source in certain cases? A quick test of using knit on a file with R & bash code results in both being executed, and variables set in R chunks being available in the console after execution, so it seems like it might work.

I would be happy to help with working on this at some point in the future if you think it is a reasonable approach and would be interested in having this in vim-r. Otherwise I can try to just come up with a simpler solution and hook it in using your suggestion above.

khughitt avatar Sep 17 '14 19:09 khughitt

If knitr already does the job, it would be easy to call knit() instead of source(). Instead of generating a file with R code, I think the algorithm would be : (1) Copy the Rnoweb code up to the cursor position, (2) add an @ symbol, and (3) call knit().

jalvesaq avatar Sep 17 '14 19:09 jalvesaq