write_cb: Portable read/write access to system clipboard

View source: R/write_cb.R

write_cbR Documentation

Portable read/write access to system clipboard

Description

These functions aim at providing portable way of reading and writing to system clipboard. The primary motivation was to smooth the process of copy-pasting computation results from R to Office programs (MSWord, LibreOffice, etc.).

Usage

write_cb(x, ...)

read_cb(...)

Arguments

x

object to be written, it is coerced to character

...

other arguments passed to/from other methods, including condesc with connection description. See Details.

Details

Interaction with system clipboard is very much system-dependent. The particular method used depends on the type of the operating system, which is queried from Sys.info()["sysname"].

write_cb expects a single argument which is written into the clipboard after being converted to character. Writing is performed via a connection description of which can be specified with condesc or the clipboard.write option. Defaults are system-specific, see below.

On Windows writing to clipboard is performed via file connection. Default description is clipboard.

On Unix-like systems a small program xclip has to be installed, see References below. Writing is performed via a pipe with description xclip -i -selection clipboard. By default we are using X selection clipboard. Alternatives are XA_PRIMARY or XA_SECONDARY. Consult further documentation of xclip.

On MacOS writing is performed via pipe using pbcopy description by default.

read_cb can be called without any arguments. Reading is performed via a connection description of which can be specified with condesc or clipboard.read option. Defaults are system specific, see below.

Reading Windows clipboard uses file connection with description clipboard.

Reading clipboard on Linux is performed via a pipe and xclip program.

Reading clipboard on MacOS uses pipe with description pbcopy.

Value

For write_cb it is NULL.

For read_cb, it is a character vector with lines of content of the clipboard.

References

Program xclip http://sourceforge.net/projects/xclip

See Also

Section "Clipboard" of help(connection).


mbojan/clipboard documentation built on June 27, 2022, 8:23 p.m.