Escaping R Code
gzagatti opened this issue · 3 comments
This is a great plugin that I use almost every day.
However, I have been facing issues with sending R code to the console. Whenever the code is small, I can send it to the console without any problem. However, when I select a big chunk and send to the console it breaks.
It seems that when the code is pasted on the console via tmux paste-buffer
, it gets somehow duplicated and I get an error. Whenever I copy and paste manually, the code is pasted correctly. Thus, I am not sure how to correct this problem.
I gave a go at escaping the R code by writing a custom function without any success:
function! SlimuxEscape_r(text)
"" Remove all empty lines and use soft linebreaks
let no_empty_lines = substitute(a:text, '\n\s*\ze\n', "", "g")
let no_empty_lines = substitute(no_empty_lines, "\n", "
", "g")
"" See if any non-empty lines sent at all
if no_empty_lines == "
"
return "
"
endif
"" Return the processed lines
return l:no_empty_lines, "
")."
"
endfunction
As an illustration, take the following code:
data.frame(
Intercept=1,
#aaaaaaaaaaaaa = aaaa$aaaaaaaaaaaaa,
#aaaaaaaaaaaaaa = aaaa$aaaaaaaaaaaaaa,
a = 23,
#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = aaaa$aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
#aaaaaaaaaaaaaaaaa = aaaa$aaaaaaaaaaaaaaaaa,
#aaaaaaaaaaaaaaaaa = aaaa$aaaaaaaaaaaaaaaaa,
#aaaaaaaaaaaaaaaa = aaaa$aaaaaaaaaaaaaaaa,
#aaa = aaaa$aaa,
#aaaaaaaaaaaaaa = aaaa$aaaaaaaaaaaaaa,
#aaaaaaaaaaaaaa = aaaa$aaaaaaaaaaaaaa,
#aaaaaaaaaaaaaaa = aaaa$aaaaaaaaaaaaaaa,
#aaaaaaaaaaaaaaa = aaaa$aaaaaaaaaaaaaaa,
#aaaaaaaaaaaaaaa = aaaa$aaaaaaaaaaaaaaa,
#aaaaaaaaaaaaaaaaaaa = aaaa$aaaaaaaaaaaaaaaaaaa,
#aaaaaaaaaaaaaaaaaaaa = aaaa$aaaaaaaaaaaaaaaaaaaa,
#aaaaaaaaaaaaaaaaaaa = aaaa$aaaaaaaaaaaaaaaaaaa,
#aaaaaaaaaaaaaaaaaaaa = aaaa$aaaaaaaaaaaaaaaaaaaa,
#aaaaaaaaaaaaaaaa = aaaa$aaaaaaaaaaaaaaaa,
b = 34,
#aaaaaaaaaaaaaaaaa = aaaa$aaaaaaaaaaaaaaaaa,
c = 56,
#aaaaaaaaaa = aaaa$aaaaaaaaaa,
#aaaaaaaaaaaaa = aaaa$aaaaaaaaaaaaa,
#aaaaaaaaaaaaaaa = aaaa$aaaaaaaaaaaaaaa,
d = 56 #,
#aaaaaaaaaaaaaaa = aaaa$aaaaaaaaaaaaaaa,
#aaaaaaaaaaaaaa = aaaa$aaaaaaaaaaaaaa,
#aaaaaaaaaaa = aaaa$aaaaaaaaaaa
)
Whenever I send to the console via :SlimuxREPLSendSelection<CR>
. The code is not pasted correctly and I get an error:
Error in data.frame(Intercept = 1, a = 23, b = 34, c = 56, aa$aaaaaaaaaaaaa, :
object 'aa' not found
However, if I copy and paste the above in the console it run without any problems.
Has anybody experienced a similar issue? Any way to fix it?
Well it's 5 years later but someone else is indeed struggling with the same thing, @gzagatti.
I've been using SLIMUX for 10 years and I've only recently started having trouble, first with phantom characters on WSL2 (got ran out of town after asking about it on StackOverflow), and then I switched to a Mac and hit this issue. Your illustration still works perfectly. It's interesting because if you take out just some of the commented lines between a = and b = , it works.
Have you found a workaround? Do you want to team up and try to figure this out?
@baogorek, I haven't been using R as frequently anymore which means I have not faced this issue as recurrently as before. I never found a workaround, so I continued using copy/paste or sourcing the file. It's a shame that the problem persists as SLIMUX is very useful otherwise.
Unfortunately, I do not have the bandwidth to work on this at the moment.
I finally figured out what's going on here. It actually has nothing to do with SLIMUX as a plugin. The problem appears to be with tmux on MacOS, and in particular the tmux paste-buffer
command. You can reproduce the problem by running:
tmux load-buffer temp.R
tmux paste-buffer
for a temp.R of the right length and composition to make it fail spectacularly. You'll see the repeated characters right on the screen.
Given I was also having trouble with SLIMUX on WSL 2, I have a new rule: SLIMUX is for true Linux only. While in MacOS, I'm going to be running SLIMUX in an ubuntu docker container. I'll be ssh-ing in and using X-forwarding to get plots (see here f](url) for a tutorial).