Imports spreadsheet data from the user's clipboard to RStudio. Also, copies full file paths if copied from an OS file navigation window.
Imported data formats in 1 of 2 ways.
If pasting to the console window, 'ctrl+alt+shift+v' will insert a tibble or vector of the copied spreadsheet data.
If pasting to the text editor window, 'ctrl+alt+shift+v' will insert an expression to produce the spreadsheet data.
To set the quick keys, use set_xlr_key_chords()
If pasting multiple spreadsheet rows, the data imports as a tibble.
If pasting a single spreadsheet row with multiple columns, the data imports as a vector.
If pasting folder and file paths from an OS navigation window, the data imports as a vector.
Arguments
- has_fieldnames
TRUE or FALSE indicating whether field names are present in the spreadsheet data you copied. If user supplies no value,
paste_from_xl()
guesses by looking at the clipboard data. If the function incorrectly guesses the presence of field names, just place T or F into the function echoed to the console. Ifhas_fieldnames
is set to either TRUE or FALSE, the data always imports as a tibble.
Value
** If user copied a single spreadsheet row or column into clipboard memory, returns a vector. ** If user copied more than one spreadsheet row or column to the clipboard, returns a tibble. ** If user copied a local file to the clipboard, returns a string with the path to the file.
Details
To set the quick keys in RStudio, run function:
set_xlr_key_chords()
.
Or, set the quick keys manually by following these RStudio instructions:
https://support.posit.co/hc/en-us/articles/206382178-Customizing-Keyboard-Shortcuts-in-the-RStudio-IDE
In Windows, path copying and pasting from a navigation window into R requires that a Powershell script be callable from the command prompt. (Sometimes Powershell might be disabled.)
Note
If you're copying a very large quantity of data from a spreadsheet,
try reading in the data instead with readxl::read_excel()
.
Examples
if(interactive()){
# Copy data from a spreadsheet into working memory by right-clicking
# with your mouse and selecting 'copy', or by using 'ctrl + c'.
# Paste the copied spreadsheet data into R by typing into the R console:
(my_data <- paste_from_xl())
paste_from_xl()
}