Search code examples
rclipboardcopy-pastewrite.table

Copy table to clipboard without quotes


I want to copy paste data to clipboard from R, and then to powerpoint. As there is a lot to copy paste, I want to eliminate as many steps as possible. The following code gets me my data, but with quotes ("") that I get to have to manually delete afterwards, which is annoying:

# Data similar to mine:
library(stringi)    
dfrm <- cbind(mtcars, str=stri_rand_strings(nrow(mtcars), 5, '[A-Z]'))
# Output similar to what I want:
a <- t(dfrm["Toyota Corolla", c("cyl", "str", "disp", "hp", "drat")])
      #
      #      Toyota Corolla
      # cyl  "4"               # Presence of a string element in 
      # str  "NVQJS"           # my vector forces all elements to 
      # disp "71.1"            # become string upon transposition
      # hp   "65"          
      # drat "4.22"   
# I want to get rid of all labels:
write.table(a, "clipboard", row.names = F, col.names = F)

      # This is what it looks like when I paste this:
      # 
      # "4"
      # "NVQJS"
      # "71.1"
      # "65"
      # "4.22"

How do I get rid of the quotes, such that my data looks like this when I paste, eliminating the need to manually delete quotes? Thanks.

      # Desired result when pasted:
      # 
      # 4
      # NVQJS
      # 71.1
      # 65
      # 4.22

Solution

  • Just add quote=FALSE to your write.table

    write.table(a, "clipboard", row.names = F, col.names = F, quote=F)