Re: [R] Program output to file using a batch command file

From: Charles C. Berry <cberry_at_tajo.ucsd.edu>
Date: Mon, 31 Dec 2007 15:13:28 -0800

On Mon, 31 Dec 2007, Jean-Victor Côté wrote:

>
> If I copy the following commands in my batch file to the R console, R
> creates a file named "basicStatsIBM.lis" with the program output in it:
>
> Sortie <- file(description = "basicStatsIBM.lis", open = "wt", blocking =
> TRUE,
> encoding = "UTF-8")
> sink(file = Sortie, append = FALSE, type = "output", split = FALSE)
> basicStats(ibm)
> close(Sortie)
>
> However, the same commands in a text file (named batch.txt, for instance)
> referred to from the R console by the command source("batch.txt") yields an
> empty "basicStatsIBM.lis" file.
>
> Why the discrepancy in processing?
> How to make the batch commands work as if the commands were pasted directly
> in the R console?
> A solution to this problem would save time and aggravation to many people.

As it happens, the R Development Core Team provides just such a solution (to 'save time and aggravation to many' of us) in the form of:

  1. EXCELLENT DOCUMENTATION to enable you to figure out why this happens
  2. flexible functions like source() with useful arguments like 'print.eval' and sensible defaults for them.

and

         3) Useful problem solving advice in the Posting Guide.

By following the advice in the Posting Guide, you would find this help page:

         ?source

and I expect see this bit:

         Arguments:

.
.
.
 	print.eval: logical; if 'TRUE', the result of 'eval(i)' is printed
 		    for  each expression 'i'; defaults to 'echo'.


---

You might be confused by the word 'printed', which seems to refer only to 
expressions that would autoprint (and not stuff like 'x <- y')

---

'Nother words use 'source("batch.txt", print.eval=TRUE)' and try the 
suggestions in the Posting Guide when you hit a snag.

Chuck


> Thank you.
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
Charles C. Berry (858) 534-2098 Dept of Family/Preventive Medicine E mailto:cberry_at_tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901

______________________________________________ R-help_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

Received on Mon 31 Dec 2007 - 23:19:08 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 31 Dec 2007 - 23:30:04 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive