Can't plot in R from tmux - r

I'm able to plot() in R from a regular terminal, but I can't do so from a tmux pseudo-tty. png() works fine but I can't write to the monitor.
UPDATE: Sorry, there's no error message. R merely fails to "print" to the monitor.
UPDATE 2: ctrl+b :showenv returns
DISPLAY=:0
SSH_AGENT_PID=1786
-SSH_ASKPASS
SSH_AUTH_SOCK=/tmp/ssh-ebteUtjL1719/agent.1719
-SSH_CONNECTION
WINDOWID=18928777
XAUTHORITY=/home/me/.Xauthority

fix in R
Sys.getenv('DISPLAY')
Sys.setenv("DISPLAY"=":0.0")
X11()
qplot(...)
.Devices
device.list()
should do it.
fix in tmux
You can also type Ctrl+b, :setenv DISPLAY :0.0 to change it from tmux rather than from R.
Why does this happen?
It might have to do with where you open the tmux (virtual terminal versus GNOME terminal) when you initially run the command tmux to initiate the session manager.
It's good to echo $DISPLAY in the terminal and Sys.getenv("DISPLAY") in R. See stuff like https://unix.stackexchange.com/questions/31283/error-in-r-unable-to-open-connection-to-x11
You can also run capabilities() in R and if capabilities()$X11 == FALSE then that's what to work on fixing.
I messed around for a while and then was able to do X11(); qplot( my.ggplot ). Check ?X11 for a little more information too.

It would help if you included the error message, but it sounds like your DISPLAY environment variable isn't set properly inside tmux. Issue echo $DISPLAY from outside your tmux session, and make sure DISPLAY is set to the same thing inside tmux.
You can use the update-environment command in tmux to configure tmux so that it automatically updates particular tmux environment variables with their values from the external environment. See the tmux manpage for details, or search the web for "tmux update-environment" for various other pages that describe this feature.

Related

Tmux split window command not working after brew upgrade

I wanted to run 'brew update' but run 'brew upgrade'.
After that, my tmux stop working on some functionalities.
For example, I cannot split windows. I have already tried using shortcut (Prefix-%), terminal command (tmux split-window), or tmux command (Prefix-:split-window). Sometimes the terminal divides the window for a fraction of time and then the new pane fades out. Sometimes nothing happens.
If tmux is detached, I can attach with tmux attach but some other commands are not working. For example, if I run tmux new-session -As "foo", it returns the string [exit] and if I inspect the return (echo $?), it returns 0.
I have already tried to run tmux without any configuration in case my tmux.conf have some problems. But when I run tmux -f /dev/null, it returns the string [exit] and if I inspect the return (echo $?), it returns 0.
The problem is that I am not sure if the problem is with tmux itself (it was upgraded to 3.2a - and I did not remember which version it was before) or if the problem is with another program or with the fact I am running with Mac M1 processor, that causes me problems in a bunch of situations.
I have already tried to downgrade tmux but there are not many materials on how to do that I the ones that I tried did not work. So I give up, especially because I was not sure if this would solve the problem.
In summary, I need some help at least to know how to best debug the problem.
Thanks!
I had the exact same problem and could fix it by just restarting my tmux session. Dettaching and reattaching is not enough.

Tmux asks for root password on every command

I recently had to reinstall my system and ever since I've been having a weird issue with tmux where it prompts me for my sudo password every time it creates a new pane or window (including when I first start it). It appears to make absolutely no difference whether I actually enter it or not; because the prompt happens after the pane/window was already created, I can just Ctrl-C out of the prompt if I want. I’m not sure if more functions are also affected which I just don't use but at least some of those I do use are definitely not (e.g. source-file).
On a sidenote, I also noted that since I changed my login shell to zsh after the reinstall, alias definitions in .zprofile do not carry over to interactive shells anymore, which they definitely did do under my previous system (although the file is definitely sourced as environment variables are set correctly even in the interactive shell). Maybe my shell environment got messed somehow and the tmux problem is just a side-effect of that?
Never mind, I found the issue: I was using a sudo call to start a daemon in my .zprofile, so when the interactive shell sourced that it caused a sudo prompt. I found a workaround which doesn't require sudo which solved the problem.

tmux attach and current working directory

I have as on single command "new" in my $HOME/.tmux.conf so I can call tmux attach as a command automatically using ssh. Recently (I believe since version 2.7) I am seeing a strange effect that if I use "tmux attach" and I do not have a session running a new session is started as expected (as I have the new command in my .tmux.conf) but the current working directory is "." if I use echo $PWD. If I use tmux without arguments to create a new session anyways I get a normal $PWD, in my case it is $HOME as I always call tmux right after logging in.
This wreaks havoc with a few shell scripts, for example the mvim script is not able to open any files in macvim any longer. If I use "cd $HOME" after using tmux attach for the first time when it created a new default session it works OK. Does anybody have any clue on how to fix that without issuing "cd $HOME"?
I just found that tmux version 2.8 fixes the problem.

Tmux not using my Powerline characters

I have been trying to update tmux and add Powerline character support in it. I am currently using oh-my-zsh with 'agnoster' theme and powerline characters and prompt are getting displayed as they should but when i start tmux session, those character on prompt disappears and _ is replaced with them.What can i do to rectify it.
My tmux.conf
Using ubuntu 16.04
Output of echo $TERM is screen-256color.
Not using tmux-powerline as it's no longer maintained.
I have also tried reinstalling Powerline.
Instead of source "/usr/local/lib/python2.7/dist-packages/powerline/bindings/tmux/powerline.conf" you should use run 'powerline-config tmux setup', which should do all the automagic for you without explicily naming paths. You can give it a try by simply executing it in your shell after starting tmux.

Start 'tmux' before Vim. The X Window system is required to run R in an external terminal

I am using a previous version of Vim-R-Plugin and pretty comfortable about its settings. Recently I upgraded the Linux system and got message never before "Start 'tmux' before Vim. The X Window system is required to run R in an external terminal.". The issue is, if I start tmux manually, the vim background were also changed weirdly and further ,rc will start a R console in a split window rather than a new window. Does somebody know the reasons and how to fix it?
This is due to styles and handling of tmux 'emulated terminal'.
At first try to simply run
tmux -2
If it does not help try add in ~/.tmux.conf:
set -g default-terminal "screen-256color"

Resources