R: Read/Write to/from the Clipboard in MS Windows

clipboard {utils} | R Documentation

## Read/Write to/from the Clipboard in MS Windows

### Description

Transfer text between a character vector and the Windows clipboard in MS Windows (only).

### Usage

    getClipboardFormats(numeric = FALSE)
    readClipboard(format = 1, raw = FALSE)
    writeClipboard(str, format = 1)

### Arguments

`numeric` | logical: should the result be in human-readable form (the default) or raw numbers?
`format` | an integer giving the desired format.
`raw` | should the value be returned as a raw vector rather than as a character vector?
`str` | a character vector or a raw vector.

### Details

The Windows clipboard offers data in a number of formats: see e.g. https://docs.microsoft.com/en-gb/windows/desktop/dataxchg/clipboard-formats.

The standard formats include

CF_TEXT | 1 | Text in the machine's locale
CF_BITMAP | 2 |
CF_METAFILEPICT | 3 | Metafile picture
CF_SYLK | 4 | Symbolic link
CF_DIF | 5 | Data Interchange Format
CF_TIFF | 6 | Tagged-Image File Format
CF_OEMTEXT | 7 | Text in the OEM codepage
CF_DIB | 8 | Device-Independent Bitmap
CF_PALETTE | 9 |
CF_PENDATA | 10 |
CF_RIFF | 11 | Audio data
CF_WAVE | 12 | Audio data
CF_UNICODETEXT | 13 | Text in Unicode (UCS-2)
CF_ENHMETAFILE | 14 | Enhanced metafile
CF_HDROP | 15 | Drag-and-drop data
CF_LOCALE | 16 | Locale for the text on the clipboard
CF_MAX | 17 | Shell-oriented formats

Applications normally make data available in one or more of these and possibly additional private formats. Use `raw = TRUE` to read binary formats, `raw = FALSE` (the default) for text formats. The current codepage is used to convert text to Unicode text, and information on that is contained in the `CF_LOCALE` format. (Take care if you are running R in a different locale from Windows.)

The `writeClipboard` function will write a character vector as text or Unicode text with standard CR-LF line terminators. It will copy a raw vector directly to the clipboard without any changes.

### Value

For `getClipboardFormats`, a character or integer vector of available formats, in numeric order. If non human-readable character representation is known, the number is returned.

For `readClipboard`, a character vector by default, a raw vector if `raw` is `TRUE`, or `NULL`, if the format is unavailable.

For `writeClipboard` an invisible logical indicating success or failure.

### Note

This is only available on Windows.

### See Also

`file` which can be used to set up a connection to a clipboard.

[Package utils version 4.0.5 Index]