Title: | Read and Write from the System Clipboard |
---|---|
Description: | Simple utility functions to read from and write to the Windows, OS X, and X11 clipboards. |
Authors: | Matthew Lincoln [aut, cre] , Louis Maddox [ctb], Steve Simpson [ctb], Jennifer Bryan [ctb] |
Maintainer: | Matthew Lincoln <[email protected]> |
License: | GPL-3 |
Version: | 0.8.0.9000 |
Built: | 2024-11-11 06:00:40 UTC |
Source: | https://github.com/mdlincoln/clipr |
Clear the system clipboard.
clear_clip(...)
clear_clip(...)
... |
Pass other options to |
This is a wrapper function for write_clip("")
Simple utility functions to read from and write to the Windows, OS X, and X11 clipboards.
The basic functions read_clip()
and write_clip()
wrap
platform-specific functions for writing values from R to the system
clipboard. read_clip_tbl()
will attempt to process the clipboard
content like a table copied from a spreadsheet program.
clipr_available()
is useful when building packages that
depend on clipr functionality.
Checks to see if the system clipboard is write-able/read-able. This may be useful if you are developing a package that relies on clipr and need to ensure that it will skip tests on machines (e.g. CRAN, Travis) where the system clipboard may not be available.
clipr_available(...) dr_clipr(...)
clipr_available(...) dr_clipr(...)
... |
Pass other options to |
clipr_available
returns a boolean value.
Prints an informative message to the console with software and system configuration requirements if clipr is not available (invisibly returns the same string)
This will automatically return FALSE
, without even performing the
check, if you are running in a non-interactive session. If you must call
this non-interactively, be sure to call using
clipr_available(allow_non_interactive = TRUE)
, or by setting the
environment variable CLIPR_ALLOW=TRUE
. Do not attempt to run
clipr non-interactively on CRAN; this will result in a failed build!
## Not run: # When using testthat: library(testthat) skip_if_not(clipr_available()) ## End(Not run)
## Not run: # When using testthat: library(testthat) skip_if_not(clipr_available()) ## End(Not run)
Read the contents of the system clipboard into a character vector.
read_clip(allow_non_interactive = Sys.getenv("CLIPR_ALLOW", interactive()))
read_clip(allow_non_interactive = Sys.getenv("CLIPR_ALLOW", interactive()))
allow_non_interactive |
By default, clipr will throw an error if run in
a non-interactive session. Set the environment variable
|
A character vector with the contents of the clipboard. If the system clipboard is empty, returns NULL
read_clip()
will not try to guess at how to parse copied text. If
you are copying tabular data, it is suggested that you use
read_clip_tbl()
.
## Not run: clip_text <- read_clip() ## End(Not run)
## Not run: clip_text <- read_clip() ## End(Not run)
read_clip()
into data frame.Transforms clipped content into a data frame by putting
read_clip()
output by using read.table()
.
read_clip_tbl(x = read_clip(), ...)
read_clip_tbl(x = read_clip(), ...)
x |
Defaults to reading from the clipboard, but can be substituted by a
character vector already generated by |
... |
Options to pass to
|
A data frame with the contents of the clipboard. If the system
clipboard is empty, returns NULL
Write a character vector to the system clipboard
write_clip( content, object_type = c("auto", "character", "table"), breaks = NULL, eos = NULL, return_new = FALSE, allow_non_interactive = Sys.getenv("CLIPR_ALLOW", interactive()), ... )
write_clip( content, object_type = c("auto", "character", "table"), breaks = NULL, eos = NULL, return_new = FALSE, allow_non_interactive = Sys.getenv("CLIPR_ALLOW", interactive()), ... )
content |
An object to be written to the system clipboard. |
object_type |
|
breaks |
The separator to be used between each element of the character
vector being written. |
eos |
The terminator to be written after each string, followed by an
ASCII |
return_new |
If true, returns the rendered string; if false, returns the original object |
allow_non_interactive |
By default, clipr will throw an error if run in
a non-interactive session. Set the environment variable
|
... |
Custom options to be passed to |
Invisibly returns the original object
On X11 systems, write_clip()
will cause either xclip (preferred) or
xsel to be called. Be aware that, by design, these processes will fork into
the background. They will run until the next paste event, when they will
then exit silently. (See the man pages for
xclip and
xsel
for more on their behaviors.) However, this means that even if you
terminate your R session after running write_clip()
, those processes will
continue until you access the clipboard via another program. This may be
expected behavior for interactive use, but is generally undesirable for
non-interactive use. For this reason you must not run write_clip()
on
CRAN, as the nature of xsel has caused issues in the past.
Call clipr_available()
to safely check whether the clipboard is readable
and writable.
## Not run: text <- "Write to clipboard" write_clip(text) multiline <- c("Write", "to", "clipboard") write_clip(multiline) # Write # to # clipboard write_clip(multiline, breaks = ",") # write,to,clipboard tbl <- data.frame(a=c(1,2,3), b=c(4,5,6)) write_clip(tbl) ## End(Not run)
## Not run: text <- "Write to clipboard" write_clip(text) multiline <- c("Write", "to", "clipboard") write_clip(multiline) # Write # to # clipboard write_clip(multiline, breaks = ",") # write,to,clipboard tbl <- data.frame(a=c(1,2,3), b=c(4,5,6)) write_clip(tbl) ## End(Not run)
Write contents of the last R expression to the clipboard
write_last_clip(...)
write_last_clip(...)
... |
Pass other options to |
This is a wrapper function for write_clip(.Last.value)