From 67becea8823d931611f91746c41561babf375479 Mon Sep 17 00:00:00 2001 From: Matthew Lincoln Date: Wed, 2 Sep 2015 17:15:33 -0400 Subject: [PATCH 1/4] Default to linux Per CRAN request, default to searcihng for xcip or xsel so that the package can work on Solaris et al. --- R/clipboard.R | 6 ++---- R/linux_clipboard.R | 30 ++++++++++++++++++++---------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/R/clipboard.R b/R/clipboard.R index 72ba225..bfca94c 100644 --- a/R/clipboard.R +++ b/R/clipboard.R @@ -16,9 +16,8 @@ read_clip <- function() { # Use the appropriate handler function chosen_read_clip <- switch(sys.type, "Darwin" = osx_read_clip, - "Linux" = linux_read_clip, "Windows" = win_read_clip, - stop("System not recognized!") + linux_read_clip ) content <- chosen_read_clip() @@ -63,9 +62,8 @@ write_clip <- function(content, sep = NULL, eos = NULL) invisible({ # Choose an operating system-specific function (stop with error if not recognized) chosen_write_clip <- switch(sys.type, "Darwin" = osx_write_clip, - "Linux" = linux_write_clip, "Windows" = win_write_clip, - stop("System not recognized!") + linux_write_clip ) # Supply the clipboard content to write and options list to this function diff --git a/R/linux_clipboard.R b/R/linux_clipboard.R index 96416e8..c8c1c4f 100644 --- a/R/linux_clipboard.R +++ b/R/linux_clipboard.R @@ -1,6 +1,16 @@ -# Function to stop the read/write and return an error of missing clipboard software. +# Determine if system has 'xclip' installed +has_xclip <- function() { + nzchar(Sys.which("xclip")) +} + +# Determine if system has 'xsel' installed +has_xsel <- function() { + nzchar(Sys.which("xsel")) +} + +# Stop read/write and return an error of missing clipboard software. notify_no_cb <- function() { - stop("Clipboard on Linux requires 'xclip' (recommended) or 'xsel'. Try using:\nsudo apt-get install xclip", + stop("Clipboard on Unix-like systems requires 'xclip' (recommended) or 'xsel'.", call.=FALSE) } @@ -10,15 +20,15 @@ notify_no_cb <- function() { # Adapted from: https://github.com/mrdwab/overflow-mrdwab/blob/master/R/readClip.R # and: https://github.com/jennybc/reprex/blob/master/R/clipboard.R linux_read_clip <- function() { - if (Sys.which("xclip") != "") { + if (has_xclip()) { con <- pipe("xclip -o -selection clipboard") - } else if (Sys.which("xsel") != "") { + } else if (has_xsel()) { con <- pipe("xsel --clipboard") } else { notify_no_cb() } content <- scan(con, what = character(), sep = "\n", - blank.lines.skip = FALSE, quiet = TRUE) + blank.lines.skip = FALSE, quiet = TRUE) close(con) return(content) } @@ -30,22 +40,22 @@ linux_read_clip <- function() { # # Targets "primary" and "clipboard" clipboards if using xclip, see: http://unix.stackexchange.com/a/69134/89254 linux_write_clip <- function(content, wc.opts) { - if (Sys.which("xclip") != "") { + if (has_xclip()) { con <- pipe("xclip -i -sel p -f | xclip -i -sel c", "w") - } else if (Sys.which("xsel") != "") { + } else if (has_xsel()) { con <- pipe("xsel -b", "w") } else { notify_no_cb() } - + # If no custom line separator has been specified, use Unix's default newline character: (\code{\n}) sep <- ifelse(is.null(wc.opts$sep), '\n', wc.opts$sep) - + # If no custom 'end of string' character is specified, then by default assign \code{eos = NULL} # Text will be sent to the clipboard without a terminator character. eos <- wc.opts$eos # Note - works the same as ifelse(is.null,NULL,wc.opts$eos) - + content <- flat_str(content, sep) writeChar(content, con = con, eos = eos) close(con) From 7691cb50bc5e868078d383ede82b2c5ca53ef6be Mon Sep 17 00:00:00 2001 From: Matthew Lincoln Date: Wed, 2 Sep 2015 17:15:56 -0400 Subject: [PATCH 2/4] clarify that xclip and xsel are required --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7901c97..88006e5 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ clipr [![CRAN status.](http://www.r-pkg.org/badges/version/clipr)](http://www.r-pkg.org/pkg/clipr) -Simple utility functions to read and write from the system clipboards of Windows, OS X, and Linux. +Simple utility functions to read and write from the system clipboards of Windows, OS X, and Unix-like systems (which require either xclip or xsel.) ```R devtools::install_github("mdlincoln/clipr") From 7a3090fa3a138b4a0e9b6e84dedee2c2be274894 Mon Sep 17 00:00:00 2001 From: Matthew Lincoln Date: Wed, 2 Sep 2015 17:16:02 -0400 Subject: [PATCH 3/4] bump version --- DESCRIPTION | 2 +- NEWS.md | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 NEWS.md diff --git a/DESCRIPTION b/DESCRIPTION index 70c1f1b..ac16f88 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: clipr Type: Package Title: Read and Write from the System Clipboard -Version: 0.1.0.9000 +Version: 0.1.1 Authors@R: c( person("Matthew", "Lincoln", email = "matthew.d.lincoln@gmail.com", role = c("aut", "cre")), person("Louis", "Maddox", role = "ctb")) diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..e32d9fc --- /dev/null +++ b/NEWS.md @@ -0,0 +1,3 @@ +## clipr 0.1.1 + +- Bug fix that removes the explicit test for "Linux" in favor of a check for "xclip" or "xsel" From 7ba8a4e701cb2f23224056b44abf23658448bc3a Mon Sep 17 00:00:00 2001 From: Matthew Lincoln Date: Wed, 2 Sep 2015 17:16:11 -0400 Subject: [PATCH 4/4] resubmission comments --- cran-comments.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cran-comments.md b/cran-comments.md index cca06b0..9cdf189 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,4 +1,9 @@ -This is my first submission. +## Resubmission +This is a resubmission. In this version I have: + +* Removed the check for a "Linux" system. Instead, if system != "Darwin" or "Windows", will assume a Unix-like system + +* Reimplemented the check for 'xclip' and/or 'xsel'. The following error will still be thrown if neither program is installed: `Error: Clipboard on Unix-like systems requires 'xclip' (recommended) or 'xsel'.` ## Test environments * local OS X install, R 3.2.2