From ff90188f41189d44d429cbfb450bb7c9080cb298 Mon Sep 17 00:00:00 2001 From: MS Berends <31037261+msberends@users.noreply.github.com> Date: Thu, 29 Mar 2018 12:56:03 +0200 Subject: [PATCH 01/10] Update .travis.yml --- .travis.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7a316275..d1821178 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,21 +1,23 @@ # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r +# Setting up R deps language: r +r: 3.2 +r_packages: covr cache: packages +# system deps os: - linux - osx +sudo: true +before_install: + - sudo apt-get -qq update + - sudo apt-get install -y xclip -r: - - 3.2 - -r_packages: - - covr - +# postrun after_success: - Rscript -e 'covr::codecov()' - notifications: email: recipients: From 2f4823f7a7866f0cfd8c5d6c6443904f58fa4a93 Mon Sep 17 00:00:00 2001 From: MS Berends <31037261+msberends@users.noreply.github.com> Date: Thu, 29 Mar 2018 13:10:55 +0200 Subject: [PATCH 02/10] Update clipboard.R --- R/clipboard.R | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/R/clipboard.R b/R/clipboard.R index c719d114..6630c07c 100644 --- a/R/clipboard.R +++ b/R/clipboard.R @@ -1,6 +1,6 @@ #' Import/export from clipboard #' -#' These are helper functions around \code{\link{read.table}} and \code{\link{write.table}} to import from and export to clipboard. The data will be read and written as tab-separated by default, which makes it possible to copy and paste from other software like Excel and SPSS without further transformation. +#' These are helper functions around \code{\link{read.table}} and \code{\link{write.table}} to import from and export to clipboard, with support for Windows, Linux and macOS. The data will be read and written as tab-separated by default, which makes it possible to copy and paste from other software like Excel and SPSS without further transformation. #' @rdname clipboard #' @name clipboard #' @inheritParams utils::read.table @@ -20,8 +20,17 @@ clipboard_import <- function(sep = '\t', na = c("", "NA", "NULL"), startrow = 1, as_vector = TRUE) { + + if (is_Windows() == TRUE) { + file <- 'clipboard' + } else { + # use xclip package + check_xclip() + file <- pipe("xclip -o -selection c", "r") + gc(FALSE) # ?gc: A call of gc causes a garbage collection to take place. + } - import_tbl <- read.delim(file = 'clipboard', + import_tbl <- read.delim(file = file, sep = sep, header = header, strip.white = TRUE, @@ -67,9 +76,18 @@ clipboard_export <- function(x, x <- get(x) - # set size of clipboard to 125% of the object size of x + if (is_Windows() == TRUE) { + # set size of clipboard to 125% of the object size of x + file <- paste0("clipboard-", size * 1.25) + } else { + # use xclip package + check_xclip() + file <- pipe("xclip -i -selection c", "w") + gc(FALSE) # ?gc: A call of gc causes a garbage collection to take place. + } + write.table(x = x, - file = paste0("clipboard-", size * 1.25), + file = file, sep = sep, na = na, row.names = FALSE, @@ -81,3 +99,12 @@ clipboard_export <- function(x, cat("Successfully exported to clipboard:", NROW(x), "obs. of", NCOL(x), "variables.\n") } } + +is_Windows <- function() { + Sys.info()['sysname'] %like% "Windows" +} +check_xclip <- function() { + if (!isTRUE(file.exists(Sys.which("xclip")[1L]))) { + stop("Please install Linux package xclip first.") + } +} From 339b445a30242fce00d7191f85535615dd1dc075 Mon Sep 17 00:00:00 2001 From: MS Berends <31037261+msberends@users.noreply.github.com> Date: Thu, 29 Mar 2018 13:12:49 +0200 Subject: [PATCH 03/10] Update test-clipboard.R --- tests/testthat/test-clipboard.R | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/testthat/test-clipboard.R b/tests/testthat/test-clipboard.R index 9fa622aa..30123564 100644 --- a/tests/testthat/test-clipboard.R +++ b/tests/testthat/test-clipboard.R @@ -1,11 +1,9 @@ context("clipboard.R") test_that("clipboard works", { - if (Sys.info()['sysname'] == "Windows") { - # why is the <<- needed? Won't work without it... - t1 <<- AMR::antibiotics - clipboard_export(t1, info = FALSE) - t2 <- clipboard_import() - expect_equal(t1, t2) - } + # why is the <<- needed? Won't work without it... + t1 <<- AMR::antibiotics + clipboard_export(t1, info = FALSE) + t2 <- clipboard_import() + expect_equal(t1, t2) }) From dbec56c68ae472063165e1967b730fea0e37cfce Mon Sep 17 00:00:00 2001 From: MS Berends <31037261+msberends@users.noreply.github.com> Date: Thu, 29 Mar 2018 13:16:08 +0200 Subject: [PATCH 04/10] Update .travis.yml --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index d1821178..0e79c45a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,9 +11,10 @@ os: - linux - osx sudo: true -before_install: - - sudo apt-get -qq update - - sudo apt-get install -y xclip +install: + - if [ $TRAVIS_OS_NAME = linux ]; then sudo apt-get -qq update; fi + - if [ $TRAVIS_OS_NAME = linux ]; then sudo apt-get install -y xclip; fi + - if [ $TRAVIS_OS_NAME = osx ]; then sudo brew install xclip; fi # postrun after_success: From fd04df5f9d30fada094a89319fa70c948843c502 Mon Sep 17 00:00:00 2001 From: MS Berends <31037261+msberends@users.noreply.github.com> Date: Thu, 29 Mar 2018 13:23:02 +0200 Subject: [PATCH 05/10] Update clipboard.R --- R/clipboard.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/clipboard.R b/R/clipboard.R index 6630c07c..bf6d758f 100644 --- a/R/clipboard.R +++ b/R/clipboard.R @@ -27,7 +27,7 @@ clipboard_import <- function(sep = '\t', # use xclip package check_xclip() file <- pipe("xclip -o -selection c", "r") - gc(FALSE) # ?gc: A call of gc causes a garbage collection to take place. + on.exit(close(file)) } import_tbl <- read.delim(file = file, @@ -82,8 +82,8 @@ clipboard_export <- function(x, } else { # use xclip package check_xclip() - file <- pipe("xclip -i -selection c", "w") - gc(FALSE) # ?gc: A call of gc causes a garbage collection to take place. + file <- pipe("xclip -i -selection primary", "w") + on.exit(close(file)) } write.table(x = x, From 9f943708cc5677c866d169aa2c0fbdb5a6523c8f Mon Sep 17 00:00:00 2001 From: MS Berends <31037261+msberends@users.noreply.github.com> Date: Thu, 29 Mar 2018 14:07:54 +0200 Subject: [PATCH 06/10] Update .travis.yml --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0e79c45a..ee3cf4a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,11 +10,10 @@ cache: packages os: - linux - osx -sudo: true install: - if [ $TRAVIS_OS_NAME = linux ]; then sudo apt-get -qq update; fi - if [ $TRAVIS_OS_NAME = linux ]; then sudo apt-get install -y xclip; fi - - if [ $TRAVIS_OS_NAME = osx ]; then sudo brew install xclip; fi + - if [ $TRAVIS_OS_NAME = osx ]; then brew install xclip; fi # postrun after_success: @@ -25,4 +24,4 @@ notifications: - m.s.berends@umcg.nl - c.f.luz@umcg.nl on_success: change - on_failure: always + on_failure: change From 136272cb7122cc406da82daf7e73925767bfa676 Mon Sep 17 00:00:00 2001 From: MS Berends <31037261+msberends@users.noreply.github.com> Date: Thu, 29 Mar 2018 14:16:42 +0200 Subject: [PATCH 07/10] Update clipboard.R --- R/clipboard.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/clipboard.R b/R/clipboard.R index bf6d758f..e3efe7f8 100644 --- a/R/clipboard.R +++ b/R/clipboard.R @@ -82,7 +82,7 @@ clipboard_export <- function(x, } else { # use xclip package check_xclip() - file <- pipe("xclip -i -selection primary", "w") + file <- pipe("xclip -i", "w") on.exit(close(file)) } From 258e0807568e7994f7ec19a93d4049c8ea446987 Mon Sep 17 00:00:00 2001 From: MS Berends <31037261+msberends@users.noreply.github.com> Date: Thu, 29 Mar 2018 14:26:26 +0200 Subject: [PATCH 08/10] Update test-clipboard.R --- tests/testthat/test-clipboard.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-clipboard.R b/tests/testthat/test-clipboard.R index 30123564..9d025bdb 100644 --- a/tests/testthat/test-clipboard.R +++ b/tests/testthat/test-clipboard.R @@ -2,8 +2,10 @@ context("clipboard.R") test_that("clipboard works", { # why is the <<- needed? Won't work without it... - t1 <<- AMR::antibiotics - clipboard_export(t1, info = FALSE) - t2 <- clipboard_import() - expect_equal(t1, t2) + if (Sys.info()['sysname'] %like% "Windows") { + t1 <<- AMR::antibiotics + clipboard_export(t1, info = FALSE) + t2 <- clipboard_import() + expect_equal(t1, t2) + } }) From e2a5202b6900922cedc433f4ca241289235a9bdd Mon Sep 17 00:00:00 2001 From: MS Berends <31037261+msberends@users.noreply.github.com> Date: Thu, 29 Mar 2018 14:47:52 +0200 Subject: [PATCH 09/10] Update test-clipboard.R --- tests/testthat/test-clipboard.R | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/testthat/test-clipboard.R b/tests/testthat/test-clipboard.R index 9d025bdb..3385f15a 100644 --- a/tests/testthat/test-clipboard.R +++ b/tests/testthat/test-clipboard.R @@ -1,11 +1,9 @@ context("clipboard.R") test_that("clipboard works", { - # why is the <<- needed? Won't work without it... - if (Sys.info()['sysname'] %like% "Windows") { - t1 <<- AMR::antibiotics - clipboard_export(t1, info = FALSE) - t2 <- clipboard_import() - expect_equal(t1, t2) - } + skip_on_os(c("linux", "solaris")) + t1 <<- AMR::antibiotics # why is the <<- needed? Won't work without it... + clipboard_export(t1, info = FALSE) + t2 <- clipboard_import() + expect_equal(t1, t2) }) From f1dbed6fcc0c5d4ec47e75c9ed97abb788881264 Mon Sep 17 00:00:00 2001 From: MS Berends <31037261+msberends@users.noreply.github.com> Date: Thu, 29 Mar 2018 14:56:40 +0200 Subject: [PATCH 10/10] Update clipboard.R --- R/clipboard.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/clipboard.R b/R/clipboard.R index e3efe7f8..48f0f785 100644 --- a/R/clipboard.R +++ b/R/clipboard.R @@ -26,7 +26,7 @@ clipboard_import <- function(sep = '\t', } else { # use xclip package check_xclip() - file <- pipe("xclip -o -selection c", "r") + file <- pipe("xclip -o", "r") on.exit(close(file)) }