3

On a Windows PC, how can I quickly print a data.frame to a printer? It doesn't have to be pretty; just trying to get it printed out for documentation purposes.

I'm aware of this SO question How to print (to paper) a nicely-formatted data frame and answers but I'm really looking for something that just prints out the text

Community
  • 1
  • 1
NoobieR
  • 33
  • 4

1 Answers1

5

Here's a bit of code that I use all the time:

print_to_printer <-function(df, addquotes = FALSE){     
write.csv(df, "c:\\PRINT_ME.txt", quote = addquotes)
shell("NOTEPAD /P c:\\PRINT_ME.txt")   
cat(quote(df), " has been printed to printer")}

then you can use it with

print_to_printer(my_df) 

if your data.frame is called my_df. Your can change the printed quotes on or off, as needed.

I have to give credit to Alin Constantin for helping me to derive the solution in R: http://alinconstantin.blogspot.com/2012/08/notepadexe-command-line-arguments.html

hackR
  • 1,459
  • 17
  • 26