[R] Can I save my console contents automatically?

Nobuaki Michihata gha10771 at gmail.com
Sat Sep 18 06:01:04 CEST 2010


Hello Greg and David,
Thank you for your help!
I forgot to write about my Mac OS version.

  System Version:	Mac OS X 10.6.4 (10F569)
  Kernel Version:	Darwin 10.4.0
  version.string R version 2.11.1 (2010-05-31)

I tried three examples. Here are the results.
Thank you.

*** ex1. commands ***
#! /usr/bin/Rscript
library(TeachingDemos)
txtStart("mylog.txt",commands = TRUE, results = TRUE, append = FALSE)
setwd("/Users/NOBU/Documents/R_data/")
summary(rnorm(100))
txtStop()
**************************
- Mac (Terminal) - The following are contents of "mylog.txt".
> setwd("/Users/NOBU/Documents/R_data/")
> summary(rnorm(100))
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max.
-2.15000 -0.59020  0.07895  0.02149  0.72740  2.40600

- Mac GUI - it could make a file named "mylog.txt", but it was empty.
The results appeared only on the console.

*** ex2. commands ***
#! /usr/bin/Rscript
sink("mylog.txt",type=c("output","message"), append = FALSE, split = TRUE)
setwd("/Users/NOBU/Documents/R_data/")
summary(rnorm(100))
sink()
**************************
- Both Mac terminal and GUI made same "mylog.txt" and the contents are
following.
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max.
-2.51600 -0.50140 -0.08050 -0.01629  0.56730  2.33300

*** ex3. commands ***
#! /usr/bin/Rscript
library(TeachingDemos)
etxtStart(file = "mylog.txt",commands = TRUE, results = TRUE, append = FALSE)
setwd("/Users/NOBU/Documents/R_data/")
summary(rnorm(100))
x <- rnorm(25)
stem(x)
summary(x)
hist(x)
etxtPlot()
etxtStop()
**************************
- MAC Terminal
--The following are results on terminal window.
Mac:R_data NOBU$ ./ex3.R
Output being copied to text file,
use etxtStop to end
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max.
-2.44300 -0.63420 -0.09356 -0.08056  0.47130  1.70200

  The decimal point is at the |

  -1 | 94311
  -0 | 998665542
   0 | 02234556
   1 | 046

   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
-1.9340 -0.9348 -0.3509 -0.2304  0.4410  1.5610
Error in dev.copy2eps(file = file, height = height, width = width) :
  can only print from a screen device
Calls: etxtPlot -> dev.copy2eps
Execution halted
-- The commands on Mac Terminal created only "Rplots.pdf" in R_data
folder, but no log files include  "mylog.txt".
   Rplots.pdf's content was a histogram without any problems.


- Mac GUI
--The following is results on GUI's console. GUI R also created a
histogram on the Quartz window.
> #! /usr/bin/Rscript
> library(TeachingDemos)
> etxtStart(file = "mylog.txt",commands = TRUE, results = TRUE, append = FALSE)
Output being copied to text file,
use etxtStop to end
etxt> setwd("/Users/NOBU/Documents/R_data/")
etxt> summary(rnorm(100))
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max.
-2.11000 -0.72410  0.07676  0.08015  0.81520  2.65300
etxt> x <- rnorm(25)
etxt> stem(x)

  The decimal point is at the |

  -2 | 1
  -1 | 5430
  -0 | 9863310
   0 | 1122466
   1 | 12369
   2 | 3

etxt> summary(x)
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max.
-2.05100 -0.77830  0.09595  0.05258  0.61970  2.32000
etxt> hist(x)
etxt> etxtPlot()
etxt> etxtStop()
[1] "/var/folders/An/AnuajzKqHdysO4TFKDOvOk+++TI/-Tmp-//RtmpDlaRj8/etxt10d63af1/mylog.txt"

-- The commands on Mac GUI created a folder named "etxt10d63af1" which
contains two files including "mylog.txt" and "plot60b7acd9.eps".
   However this didn't create any folders or files in R_data.
-- The content of "mylog.txt" is following.



More information about the R-help mailing list