mdlincoln / clipr

R functions for reading and writing from the system clipboard
http://matthewlincoln.net/clipr/
152 stars 24 forks source link

Running xsel hangs on RStudio #54

Closed csgillespie closed 3 years ago

csgillespie commented 4 years ago

Running system2("xsel", "--clipboard") causes my machine to hang (could be an i3 thing) when using RStudio console.

Changing

has_xsel <- function() has_util(c("xsel", "--clipboard"))

to

#linux_clipboard.R
has_xsel <- function() has_util(c("xsel", "--clipboard", "--output"))

Solves my issues.

The documentation suggests that this is the correct thing to do. It states that the behaviour depends on whether input / output are ttys:

   By default, this program outputs the selection without modification if both standard input  and
   standard  output  are  terminals (ttys). Otherwise, the current selection is output if standard
   output is not a terminal (tty), and the selection is set from standard input if standard  input
   is not a terminal (tty). If any input or output options are given then the program behaves only
   in the requested mode.
   If both input and output is required then the previous selection is  output  before  being  re‐
   placed by the contents of standard input.

mdlincoln commented 4 years ago

Thanks for this detailed report. I'll be able to take a closer look shortly.

mdlincoln commented 3 years ago

Thanks for your patience @csgillespie. It looks like this bug also caused read_clip() to hang when run from RStudio - my colleague who has a Linux machine using the KWin window manager helped to diagnose that. Can you give this a spin and check if read/write is working for you?

devtools::install_github(“mdlincoln/clipr”, ref=“xsel-read-output”)

csgillespie commented 3 years ago

Seems to work for me.

To test I uninstalled clip

sudo apt remove xclip

Then ran

devtools::install_github("mdlincoln/clipr", ref="xsel-read-output")
clipr::write_clip("hello")
clipr::read_clip()

in RStudio

mdlincoln commented 3 years ago

Alright. I'll ship this off to CRAN.

mdlincoln commented 3 years ago

Now shipped to CRAN.

kevinushey commented 3 years ago

Thank you for taking a look so quickly!