Skip to content

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

Description

@mbacou

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

Activity

  1. kodonnell commented on Sep 6, 2017

    @kodonnell

    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

  2. st-pasha commented on Feb 5, 2018

    @st-pasha
    Contributor

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

  3. MichaelChirico commented on May 31, 2020

    @MichaelChirico
    Member

    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...

  4. jangorecki commented on May 31, 2020

    @jangorecki
    Member

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

  5. ben-schwen commented on Oct 23, 2025

    @ben-schwen
    Member

    It's basically a switch between OS in fread.R:

    • Windows use readClipboard
    • MacOS use system(pbpaste)
    • Linus use either xclip or xsel
  6. AmanKashyap0807 commented on Feb 8, 2026

    @AmanKashyap0807

    Hi everyone,

    I was looking into this and it seems the Windows failure happens because fread() is trying to execute "clipboard-128" as a shell command, but Windows doesn't recognize it as a valid command.

    From the discussion, it looks like this could be handled with a small OS-specific switch in fread.R, as @ben-schwen suggested.

    For Windows, I see we could use the built-in readClipboard() function. But I also noticed in the StackOverflow thread that @MichaelChirico shared, there's another approach using PowerShell's Get-Clipboard command, which could work for modern Windows systems (Win10+). From what I have researched, Get-Clipboard handles different clipboard formats better than readClipboard() , though I'm not entirely sure about the format handling differences between the two.

    If we go the PowerShell route, we could treat it as a system command with the trailing space (like how @st-pasha works on macOS).

    What do you all think? I'd be happy to explore either direction or test both if that helps.

  7. added a commit that references this issue on Feb 9, 2026
    546de99
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions