mirror of
https://github.com/msberends/AMR.git
synced 2024-12-26 19:26:12 +01:00
add clipbaord support for Linux and macOS
This commit is contained in:
commit
2647dacc0a
18
.travis.yml
18
.travis.yml
@ -1,25 +1,27 @@
|
|||||||
# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r
|
# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r
|
||||||
|
|
||||||
|
# Setting up R deps
|
||||||
language: r
|
language: r
|
||||||
|
r: 3.2
|
||||||
|
r_packages: covr
|
||||||
cache: packages
|
cache: packages
|
||||||
|
|
||||||
|
# system deps
|
||||||
os:
|
os:
|
||||||
- linux
|
- linux
|
||||||
- osx
|
- osx
|
||||||
|
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 brew install xclip; fi
|
||||||
|
|
||||||
r:
|
# postrun
|
||||||
- 3.2
|
|
||||||
|
|
||||||
r_packages:
|
|
||||||
- covr
|
|
||||||
|
|
||||||
after_success:
|
after_success:
|
||||||
- Rscript -e 'covr::codecov()'
|
- Rscript -e 'covr::codecov()'
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
email:
|
email:
|
||||||
recipients:
|
recipients:
|
||||||
- m.s.berends@umcg.nl
|
- m.s.berends@umcg.nl
|
||||||
- c.f.luz@umcg.nl
|
- c.f.luz@umcg.nl
|
||||||
on_success: change
|
on_success: change
|
||||||
on_failure: always
|
on_failure: change
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#' Import/export from clipboard
|
#' 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
|
#' @rdname clipboard
|
||||||
#' @name clipboard
|
#' @name clipboard
|
||||||
#' @inheritParams utils::read.table
|
#' @inheritParams utils::read.table
|
||||||
@ -21,7 +21,16 @@ clipboard_import <- function(sep = '\t',
|
|||||||
startrow = 1,
|
startrow = 1,
|
||||||
as_vector = TRUE) {
|
as_vector = TRUE) {
|
||||||
|
|
||||||
import_tbl <- read.delim(file = 'clipboard',
|
if (is_Windows() == TRUE) {
|
||||||
|
file <- 'clipboard'
|
||||||
|
} else {
|
||||||
|
# use xclip package
|
||||||
|
check_xclip()
|
||||||
|
file <- pipe("xclip -o", "r")
|
||||||
|
on.exit(close(file))
|
||||||
|
}
|
||||||
|
|
||||||
|
import_tbl <- read.delim(file = file,
|
||||||
sep = sep,
|
sep = sep,
|
||||||
header = header,
|
header = header,
|
||||||
strip.white = TRUE,
|
strip.white = TRUE,
|
||||||
@ -67,9 +76,18 @@ clipboard_export <- function(x,
|
|||||||
|
|
||||||
x <- get(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", "w")
|
||||||
|
on.exit(close(file))
|
||||||
|
}
|
||||||
|
|
||||||
write.table(x = x,
|
write.table(x = x,
|
||||||
file = paste0("clipboard-", size * 1.25),
|
file = file,
|
||||||
sep = sep,
|
sep = sep,
|
||||||
na = na,
|
na = na,
|
||||||
row.names = FALSE,
|
row.names = FALSE,
|
||||||
@ -81,3 +99,12 @@ clipboard_export <- function(x,
|
|||||||
cat("Successfully exported to clipboard:", NROW(x), "obs. of", NCOL(x), "variables.\n")
|
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.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
context("clipboard.R")
|
context("clipboard.R")
|
||||||
|
|
||||||
test_that("clipboard works", {
|
test_that("clipboard works", {
|
||||||
if (Sys.info()['sysname'] == "Windows") {
|
skip_on_os(c("linux", "solaris"))
|
||||||
# why is the <<- needed? Won't work without it...
|
t1 <<- AMR::antibiotics # why is the <<- needed? Won't work without it...
|
||||||
t1 <<- AMR::antibiotics
|
clipboard_export(t1, info = FALSE)
|
||||||
clipboard_export(t1, info = FALSE)
|
t2 <- clipboard_import()
|
||||||
t2 <- clipboard_import()
|
expect_equal(t1, t2)
|
||||||
expect_equal(t1, t2)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user