Learn R Programming

bannerCommenter (version 1.0.0)

copy_to_clipboard: Transfer text strings to the clipboard ready for paste

Description

This is only guaranteed for Windows; in the case of Linux you will need to have the xclip command installed and visible on the PATH and for Mac OS you will need to have pbcopy similarly available. In any case the transfer to the clipboard is only activated while in an interactive session.

Usage

copy_to_clipboard(x, ..., file = con)

Arguments

x

a characeter string vector

...

additional arguments as for cat

file

a file or connection (usually left at the default)

Value

x, invisibly (as for a print method)

Details

It behaves like base::cat but differs in three respects.

First, if file is left missing, in an interactive session, the default file is a clipboard device, if possible.

Second, the return value is invisible(x) rather than invisible(NULL) as it is for base::cat.

Third, it only has a copying side-effect if used in an interactive session. In a non-interactive session it merely returns the x argument, invisibly.

Note the on Windows the function utils::writeClipboard offers a much more extensive range of possibilities for communicating with the clipboard device, but this facility is only available on Windows.