I'm working with R in vim (with vim-slime and nvim terminal). This workflow is super-simple, I'm just selecting a bunch of lines and sending it into terminal through a short-cut.
Assume that I'm working of a peace of code like:
r %>%
filter(label %in% intrest_lbs) %>%
group_by(bin) %>%
mutate(percentage = sum_N / sum(sum_N)) %>%
ungroup() %>%
complete(bin, label, fill = list(percentage = 0)) %>%
mutate(label = fct_relevel(label, intrest_lbs)) %>%
filter(bin <= 14) %>%
ggplot(aes(x = bin, y = percentage, fill = label))
geom_area(alpha = 0.6, size = 0.3, colour = "black")
scale_y_continuous(labels = scales::percent)
labs(title = condition, x = "Bin [s]", y = "Perc of sacc. [%]")
It's quite often that I want to check some intermediate results of this pipeline, let's say i just wont to check that the first mutate works as expected. I'm looking for a neat way of selecting first four lines, but without last pipe operator(%>%) in order to sent it into R interpreter without error.
So I want to select:
r %>%
filter(label %in% intrest_lbs) %>%
group_by(bin) %>%
mutate(percentage = sum_N / sum(sum_N))
And nothing more. Some smart mapping will be super helpful.
CodePudding user response:
You can create a mapping to send any visual selected region like so:
xmap <LEADER>s <Plug>SlimeRegionSend
Then it's up to you how best to visually select the region. For your example, with the cursor on the first column of the first line (and after you've transitioned to visual mode) you could do:
3jt%
And then do <LEADER>s
to send it.