jalvesaq / Nvim-R

Vim plugin to work with R
GNU General Public License v2.0
968 stars 125 forks source link

Recognize `targets` chunk as R code block in Rmd files #724

Closed alaindanet closed 10 months ago

alaindanet commented 1 year ago

Nvim-R does not recognize targets chunk as code block containing R code in Rmd files.

targets chunks contains R code that is managed by the targets R package to build a analysis pipeline.

Is there an option to set Nvim-R to behave with targets chunk as r chunk (i.e. sending code lines to the terminal, etc...) ?

Currently the plugin returns Not inside an R chunk. when I try to send lines inside targets chunks.

jalvesaq commented 1 year ago

I never used targets. Indeed, this is the first time that I know about it. What specifically do you need? Sending code from (Neo)Vim from {targets chunks to R? Syntax highlight of {targets chunks? The pattern to recognize chunks of R code in Rmd files is hardcoded in Nvim-R/ftplugin/rmd_nvimr.vim, Nvim-R/R/start_r.vim, R-Vim-runtime/syntax/rmd.vim, and R-Vim-runtime/indent/rmd.vim. We could create a variable to replace "r" with whatever the user wanted, in this case, "r\|targets", but I don't know if this would be enough, and, since I'm not going to use targets it would be better if someone else wrote a pull request for this.

alaindanet commented 1 year ago

Thank you so much for your answer. I have tried to spot the places where the changes could be made after you pointed the files:

            let i = search("^[ \t]*```[ ]*{\\(r\\|python\\)", "bnW")

If you think that those changes are the ones to implement, I will give a try!

jalvesaq commented 1 year ago

Yes, please try it. I suggest that you create a variable, perhaps named R_chunk_pattern in your init.vim:

R_chunk_pattern = 'r\|targets'

And, then, replace as in the example:

            let i = search("^[ \t]*```[ ]*{\\(" . R_chunk_pattern . "\\|python\\)", "bnW")

I suggest creating a variable because we don't know if another pattern in the future will have to be recognized as an indicator of an R chunk.