jalvesaq / Nvim-R

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

Feature request: Add iTerm2 in-line image support. #50

Closed zhmiao closed 8 months ago

zhmiao commented 8 years ago

Since new iTerm2 supports in-line images, I am wondering whether it is possible to output R graphs directly into iTerm so I don't have to use X11 anymore. iTerm image viewer is imgcat and there is an external matplotlib backend for iterm too. In addition, iTerm can also view pdfs (termpdf), although it is really beta for now.

jalvesaq commented 8 years ago

If someone writes the R code necessary for this, I can integrate it into nvimcom and, if necessary, add a key binding to Nvim-R to call it. Does the image display in a Tmux pane? Does it display in Neovim terminal inside iTerm2?

jalvesaq commented 8 years ago

It's also possible to display images in mlterm on Linux using img2sixel, but it does not work inside of either Neovim terminal or Tmux.

zhmiao commented 8 years ago

Yes, neovim in iTerm2 don't show images either. This is the related issue https://github.com/neovim/neovim/issues/4349 it is still open. It seems w3m in terminal mode in neovim can show images, but I don't think it is useful for graphs in Nvim-R

jalvesaq commented 8 years ago

w3m will be useful if we display the image in an html file:

<html><body><img src="image.png"></body></html>
zhmiao commented 8 years ago

Yeah! if we can view graphs within neovim, that would be so cool

jalvesaq commented 8 years ago

What I don't know is how to make all plot commands to output a png file. If plot(0) made a png, Nvim-R could start a new terminal, create the html to display the image and call w3m. Unfortunately, it would not work if inside Tmux.

zhmiao commented 8 years ago

is it possible to integrate :terminal command?

jalvesaq commented 8 years ago

Yes, Nvim-R already uses termopen() (which is the same :terminal called in a different way) to start R.

zhmiao commented 8 years ago

right, I forgot, it seems to output graphs to neovim terminal need some modifications in R itself

jalvesaq commented 8 years ago

R has many graphics devices (png, jpg, svg, X11, etc...). I think what we need is a new graphics device that do two things:

  1. Create a PNG file.
  2. Send a message to Nvim-R about the newly created file.

Nvim-R would react to the message and display the PNG. If there was a image already being displayed, w3m would first be closed and then called again.

zhmiao commented 8 years ago

Are you familiar with how R markdown works? I am not sure how they show pictures in these markdown files

jalvesaq commented 8 years ago

I don't use markdown. Do you have an link to an example?

zhmiao commented 8 years ago

Maybe you can check this link R_Markdown And this is their repo

jalvesaq commented 8 years ago

The links are for RStudio, not for Vim. RStudio is a Qt application and it has its own graphics device. Because Qt is a GUI toolkit, it's easy to integrate graphical things in it.

zhmiao commented 8 years ago

I see. Is making a new graphic device complicated?

jalvesaq commented 8 years ago

I don't know to make one, and I don't have time to look at this. If you can create the new graphic device, I can integrate it into Neovim. However, there is another problem: the size of the window displaying the image would be difficult to control. See: https://github.com/jalvesaq/Nvim-R/issues/33

zhmiao commented 8 years ago

yes, let me look at this.

nacnudus commented 8 years ago

I have had a look at this. Creating a new graphics device seems hard. Knitr uses the evaluate package to watch for changes in the graphics device.

Relevant files:

Relevant commands:

Someone has been thinking about a better way to do this from within R, but has made no progress for a while. https://github.com/pmur002/R-display-list/blob/master/capture.plots.R

The markdown package is R, not RStudio, though it was developed by the RStudio company.

randy3k commented 8 years ago

I think there is a major issue in implementing a new graphic device for imagecat. In R, a graphic is not ready to save/print until dev.off() is invoked. For knitr/rmarkdown, it is easier for them because they know when a plot is ready.

jalvesaq commented 8 years ago

w3m 0.5.3+git20151119 can display images in tmux 2.1. So, if this feature was implemented it could work in both Mac OS X and Linux.

jalvesaq commented 8 months ago

Nvim-R is being superseded by R.nvim, a new project that will be inaugurated in a week at the R-nvim organization. Please, check out tmp-Nvim-R and help us to find the last remaining bugs before R.nvim inauguration. When the project is officially started, you will be able to open issues there and request new features.

Nvim-R will remain alive as a feature-frozen project for Vim users. If you want to know the reason, please, see this discussion.