How to export data to Clipboard

Sometimes you just want to copy the data and paste to other applications like Excel, Word, Keynote, Numbers, etc. We’re plannning to introduce such in future releases with a click of a button, but for now you can workaround to do this by writing a custom R function with ‘R Script’ like below.

write_clipboard <- function(data){
  clip <- pipe("pbcopy", "w")
  write.table(data, clip)
  close(clip)
  data
}

Once you save this, then you can call this function ‘write_clipboard’ in the command input.

This is similar to what I have shown for exporting data in JSON, in case you’re interested in.

Hello.
I’m trying to repeat the steps in this guide, but copying to the clipboard is not happening. Moreover, the buffer stores the old data that was before the script was launched.

“name”: “Exploratory”,
“repository”: “https://github.com/exploratory-io/tam”,
“rversion”: “3.3”,
“single-instance”: true,
“version”: “3.3.0.2_WIN”,
“webkit”: { “plugin”: true },
“Windows”, “>= 8 x64”, “build 9200”, “x86-64”

Sincerely, Eugene

I have tested only on Mac, so maybe Windows specific issue. I’ll test it out on Windows and let you know.

Cheers,
Kan

Thank you. I hope everything will turn out.

Could you please try if this works for you on Windows?

write_clipboard <- function(data, size = 4096) {
  clip <- paste('clipboard-', size, sep = '')
  f <- file(description = clip, open = 'w')
  write.table(data, f, row.names = FALSE, sep = '\t')
  close(f)
  data
}

Super! It works! Thank you so much.

Great!

For Mac Users, by passing row.names = FALSE and sep = \t to write.table like below, you can paste your data into other App like Number in correct tabular format.

  clip <- pipe("pbcopy", "w")
  write.table(`_tam_flattenDataFrame`(data), clip, row.names = FALSE, sep = '\t')
  close(clip)

By the way, this will be provided as one of the menus in the next release, v3.4!