write_clip Function in R (2 Examples) | Write Character Vector to System Clipboard


This tutorial explains how to apply the write_clip function to copy data to the clipboard in the R programming language.

The tutorial will consist of these contents:

Let’s get started…


Example 1: Copy Data Frame to Clipboard Using write_clip() Function

Example 1 shows how to copy a data frame to the clipboard using the write_clip function in the R programming language.

For this example, we first have to create a data frame:

data <- data.frame(x1 = 5:10,    # Create example data frame
                   x2 = LETTERS[10:15],
                   x3 = 5)
data                             # Print example data frame


table 1 data frame write_clip function


By running the previous code, we have created Table 1, i.e. a data frame with six rows and three columns.

Next, we can apply the write_clip function of the clipr package to this data frame to save it to the clipboard:

clipr::write_clip(data)          # Apply write_clip

After running the previous R syntax, we can press the keys Ctrl + v to paste our data:

# x1	x2	x3
# 16	yyy	J
# 15	yyy	K
# 14	yyy	L
# 13	yyy	M
# 12	yyy	N
# 11	yyy	O

We can use this method to export our data frame to external files such as TXT, Excel XLSX, or CSV files.


Example 2: Copy Vector to Clipboard Using write_clip() Function

Similar to Example 1, we can use the write_clip function to copy and paste a vector object.

Let’s create an exemplifying vector:

vec <- 1:6                       # Create example vector
vec                              # Print example vector
# [1] 1 2 3 4 5 6

Next, let’s apply the write_clip command:

clipr::write_clip(vec)           # Apply write_clip

The output below shows what gets printed when we press Ctrl + v.

# 1
# 2
# 3
# 4
# 5
# 6


Video & Further Resources

Do you want to know more about the usage of the write_clip function? Then you may have a look at the following video on my YouTube channel. I explain the R code of this article in the video.


The YouTube video will be added soon.


Furthermore, you might want to have a look at some of the other articles on my website. I have published several tutorials already:


In this tutorial you have learned how to apply the write_clip function in the R programming language. If you have additional comments or questions, let me know in the comments below.


Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.