1

I tried to save screen text to a file by using the sink() function. The file was created but without any data inside it.What did I do wrong? Here my toy code:

sink("sink3.txt")
df <- read.table(text = " color birds    wolfs     
                  red           9         7 
                 red           8         4 
                 red           2         8 
                 red           2         3 
                 black         8         3 
                 black         1         2 
                 black         7         16 
                 black         1         5 
                 black         17        7 
                 black         8         7 
                 black         2         7 
                 green         20        3 
                 green         6         3 
                 green         1         1 
                 green         3         11 
                 green         30         1  ",header = TRUE)
lm<-lm(birds ~ color + wolfs , data = df)
summary(lm)
sink() 
mql4beginner
  • 2,193
  • 5
  • 34
  • 73
  • Your code works for me (win10/R-3.2.3-x64 and linux/R-3.2.3-x64). Do you have the file open elsewhere, perhaps in an editor? – r2evans Feb 23 '16 at 11:28
  • I restarted my computer and now it works. – mql4beginner Feb 23 '16 at 11:49
  • Hello @r2evans, Do you know why the sink does not print to file errors? for example if I do an lm without the data=df the sink function does not save the data / text to the file. – mql4beginner Feb 23 '16 at 13:05
  • 1
    Read `help('sink')`, specifically the description of `type` options. As far as the restart goes, that's not uncommon with nested calls to `sink`, whether intentional or otherwise. Sometimes `showConnections()` can show you open connections indicating mid-execution sinks. – r2evans Feb 25 '16 at 18:42

0 Answers0