This article describes how to read and write data from the clipboards using the R package clipr, which works well on Windows, OS X, and Unix-like systems.
Note that on Linux, you will need to install the system requirement, either
xsel. This can be done using for example
apt-get install xclip.
- Install from CRAN
- Load the package:
Copy any data into R
my_data <- read_clip() my_data
Copy data table from excel and import in R
read_clip_tbl() function will try to parse clipboard contents from spreadsheets into data frames directly.
Step 1. Copy the data from excel
Step 2. Import the data from the clipboard into R
my_data <- read_clip_tbl() my_data
## # A tibble: 11 x 6 ## name mpg cyl disp hp drat ## <chr> <dbl> <int> <dbl> <int> <dbl> ## 1 Mazda RX4 21 6 160 110 3.9 ## 2 Mazda RX4 Wag 21 6 160 110 3.9 ## 3 Datsun 710 22.8 4 108 93 3.85 ## 4 Hornet 4 Drive 21.4 6 258 110 3.08 ## 5 Hornet Sportabout 18.7 8 360 175 3.15 ## 6 Valiant 18.1 6 225 105 2.76 ## # … with 5 more rows
Write data from R to clipboard
Write a data frame
- Write the data to the clipboard:
- Paste the data into Excel:
ctrl + c
clipr returns the same object that was passed in.
res <- write_clip(c("Text", "for", "clipboard")) res
##  "Text" "for" "clipboard"
To capture the string that clipr writes to the clipboard, specify
return_new = TRUE. Character vectors with length > 1 will be collapsed with system-appropriate line breaks, unless otherwise specified
cb <- write_clip(c("Text", "for", "clipboard"), return_new = TRUE) cb
##  "Text\nfor\nclipboard"
cb <- write_clip(c("Text", "for", "clipboard"), breaks = ", ", return_new = TRUE) cb
##  "Text, for, clipboard"
Recommended for you
This section contains best data science and self-development resources to help you on your path.
Coursera - Online Courses and Specialization
- Course: Machine Learning: Master the Fundamentals by Stanford
- Specialization: Data Science by Johns Hopkins University
- Specialization: Python for Everybody by University of Michigan
- Courses: Build Skills for a Top Job in any Industry by Coursera
- Specialization: Master Machine Learning Fundamentals by University of Washington
- Specialization: Statistics with R by Duke University
- Specialization: Software Development in R by Johns Hopkins University
- Specialization: Genomic Data Science by Johns Hopkins University
Popular Courses Launched in 2020
- Google IT Automation with Python by Google
- AI for Medicine by deeplearning.ai
- Epidemiology in Public Health Practice by Johns Hopkins University
- AWS Fundamentals by Amazon Web Services
- The Science of Well-Being by Yale University
- Google IT Support Professional by Google
- Python for Everybody by University of Michigan
- IBM Data Science Professional Certificate by IBM
- Business Foundations by University of Pennsylvania
- Introduction to Psychology by Yale University
- Excel Skills for Business by Macquarie University
- Psychological First Aid by Johns Hopkins University
- Graphic Design by Cal Arts
Amazing Selling Machine
- Free Training - How to Build a 7-Figure Amazon FBA Business You Can Run 100% From Home and Build Your Dream Life! by ASM
Books - Data Science
- Practical Guide to Cluster Analysis in R by A. Kassambara (Datanovia)
- Practical Guide To Principal Component Methods in R by A. Kassambara (Datanovia)
- Machine Learning Essentials: Practical Guide in R by A. Kassambara (Datanovia)
- R Graphics Essentials for Great Data Visualization by A. Kassambara (Datanovia)
- GGPlot2 Essentials for Great Data Visualization in R by A. Kassambara (Datanovia)
- Network Analysis and Visualization in R by A. Kassambara (Datanovia)
- Practical Statistics in R for Comparing Groups: Numerical Variables by A. Kassambara (Datanovia)
- Inter-Rater Reliability Essentials: Practical Guide in R by A. Kassambara (Datanovia)
- R for Data Science: Import, Tidy, Transform, Visualize, and Model Data by Hadley Wickham & Garrett Grolemund
- Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow: Concepts, Tools, and Techniques to Build Intelligent Systems by Aurelien Géron
- Practical Statistics for Data Scientists: 50 Essential Concepts by Peter Bruce & Andrew Bruce
- Hands-On Programming with R: Write Your Own Functions And Simulations by Garrett Grolemund & Hadley Wickham
- An Introduction to Statistical Learning: with Applications in R by Gareth James et al.
- Deep Learning with R by François Chollet & J.J. Allaire
- Deep Learning with Python by François Chollet
Give a comment