Rdatatable / data.table

R's data.table package extends data.frame:
http://r-datatable.com
Mozilla Public License 2.0
3.57k stars 974 forks source link

fread from "clipboard" or "clipboard-128" (on Windows) fails #1292

Open mbacou opened 9 years ago

mbacou commented 9 years ago

Just noticed (say you "copy" delimited data from a text editor or from MSExcel and want to "paste" as data.table into an R workspace).


# this works
df <- read.delim("clipboard-128")

# this fails
dt <- fread("clipboard-128")
# Error in fread("clipboard-128") : 
#   Unable to open file after 5 attempts (error 3): C:\Users\mbacou\AppData\Local\Temp\RtmpUDARkO\file7643a2c3ff3
# In addition: Warning messages:
#1: running command 'C:\Windows\system32\cmd.exe /c (clipboard-128) > C:\Users\mbacou\AppData\Local\Temp\RtmpUDARkO\file7643a2c3ff3' had status 1 
#2: In shell(paste("(", input, ") > ", tt, sep = "")) :
#   '(clipboard-128) > C:\Users\mbacou\AppData\Local\Temp\RtmpUDARkO\file7643a2c3ff3' execution # failed with error code 1
kodonnell commented 7 years ago

I'd recommend not doing this, for a few reasons:

  1. it encourages non-reproducible code in projects
  2. I suspect this is a very small use case ...
  3. a trivial solution already exists - just copy into notepad, save as a file, then load it. In most cases, if the file is already in a text editor (or Excel) you can read directly from the file without copy/paste ...

I'm a fan of the 'just because we can do something, doesn't mean we should' motto

st-pasha commented 6 years ago

On MacOS it's as simple as fread("pbpaste "). There are probably similar simple ways of accomplishing this on other platforms too.

MichaelChirico commented 4 years ago

Could someone on Windows try one of these solutions:

https://stackoverflow.com/questions/17819814/how-can-you-get-the-clipboard-contents-with-a-windows-command

The idea would be to try something like fread("paste ") [NB: the space is required for fread to treat it as a shell command]

Another possibility is that this issue is just #561 in disguise...

jangorecki commented 4 years ago

Or Get-Clipboard as mentioned in SO. This should be already shipped on recent windowses.