R 2.5.1 - Rscript through tee

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

R 2.5.1 - Rscript through tee

François Pinard
Hi, people.

I met a little problem for which someone might have a solution.  Let's
say I have an executable file (named "pp.R") with this contents:

   #!/usr/bin/Rscript
   options(echo=TRUE)
   a <- 1
   Sys.sleep(3)
   a <- 2

If I execute "./pp.R" at the shell prompt, the output shows the timely
progress of the script as expected.  If I use "./pp.R | tee OUT"
instead, the output seems buffered and I see it all at once at the end.

The problem does not come from the "tee" program, as if I use this
command:

   (echo a; sleep 5; echo b) | tee OUT

the output is timely, not batched.

So, is there a way to tell R (or Rscript) that standard output should be
unbuffered, even if it is not directly connected to a terminal?

In case useful, here is local R information:

Version:
 platform = x86_64-unknown-linux-gnu
 arch = x86_64
 os = linux-gnu
 system = x86_64, linux-gnu
 status =
 major = 2
 minor = 5.1
 year = 2007
 month = 06
 day = 27
 svn rev = 42083
 language = R
 version.string = R version 2.5.1 (2007-06-27)

Locale:
LC_CTYPE=fr_CA.UTF-8;LC_NUMERIC=C;LC_TIME=fr_CA.UTF-8;LC_COLLATE=fr_CA.UTF-8;LC_MONETARY=fr_CA.UTF-8;LC_MESSAGES=fr_CA.UTF-8;LC_PAPER=fr_CA.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=fr_CA.UTF-8;LC_IDENTIFICATION=C

Search Path:
 .GlobalEnv, package:stats, package:utils, package:datasets, fp.etc, package:graphics, package:grDevices, package:methods, Autoloads, package:base

--
François Pinard   http://pinard.progiciels-bpi.ca

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: R 2.5.1 - Rscript through tee

Dirk Eddelbuettel

On 26 August 2007 at 22:47, François Pinard wrote:
| I met a little problem for which someone might have a solution.  Let's
| say I have an executable file (named "pp.R") with this contents:
|
|    #!/usr/bin/Rscript
|    options(echo=TRUE)
|    a <- 1
|    Sys.sleep(3)
|    a <- 2
|
| If I execute "./pp.R" at the shell prompt, the output shows the timely
| progress of the script as expected.  If I use "./pp.R | tee OUT"
| instead, the output seems buffered and I see it all at once at the end.
|
| The problem does not come from the "tee" program, as if I use this
| command:
|
|    (echo a; sleep 5; echo b) | tee OUT
|
| the output is timely, not batched.
|
| So, is there a way to tell R (or Rscript) that standard output should be
| unbuffered, even if it is not directly connected to a terminal?

Use explicit print statements, e.g.  print(a <- 1)

Also, you still have little as an alternate, at least on Unix [1].  Littler5D
actually won't show anything unless you explicitly call cat() or print(), but
then it does:

qa-v40z1:~/svn/hancock/app/aggposview> cat /tmp/fp2.r
#!/usr/bin/env r

options(echo=TRUE)
cat(a <- 1, "\n")
Sys.sleep(3)
cat(a <- 2, "\n")
foo:~> /tmp/fp2.r | tee /tmp/fp2.r.out
1
2
foo:~>

Littler is an 'all-in' binary and starts and runs demonstrably faster than
Rscript.

Hth, Dirk
 
[1] And despite the rather petty refusal of Rscript's main author to a least
give a reference to littler in Rscript's documentation, let alone credit as
'we were there first', the fact remains that littler became available in Sep
2006 whereas Rscript was not released until R 2.5.0 a good six month
later. Oh well.



| In case useful, here is local R information:
|
| Version:
|  platform = x86_64-unknown-linux-gnu
|  arch = x86_64
|  os = linux-gnu
|  system = x86_64, linux-gnu
|  status =
|  major = 2
|  minor = 5.1
|  year = 2007
|  month = 06
|  day = 27
|  svn rev = 42083
|  language = R
|  version.string = R version 2.5.1 (2007-06-27)
|
| Locale:
| LC_CTYPE=fr_CA.UTF-8;LC_NUMERIC=C;LC_TIME=fr_CA.UTF-8;LC_COLLATE=fr_CA.UTF-8;LC_MONETARY=fr_CA.UTF-8;LC_MESSAGES=fr_CA.UTF-8;LC_PAPER=fr_CA.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=fr_CA.UTF-8;LC_IDENTIFICATION=C
|
| Search Path:
|  .GlobalEnv, package:stats, package:utils, package:datasets, fp.etc, package:graphics, package:grDevices, package:methods, Autoloads, package:base
|
| --
| François Pinard   http://pinard.progiciels-bpi.ca
|
| ______________________________________________
| [hidden email] 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.

--
Three out of two people have difficulties with fractions.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: R 2.5.1 - Rscript through tee

François Pinard
[Dirk Eddelbuettel]
>[François Pinard]

>>    #!/usr/bin/Rscript
>>    options(echo=TRUE)
>>    a <- 1
>>    Sys.sleep(3)
>>    a <- 2

>> If I execute "./pp.R" at the shell prompt, the output shows the
>> timely progress of the script as expected.  If I use "./pp.R | tee
>> OUT" instead, the output seems buffered and I see it all at once at
>> the end.  [...] So, is there a way to tell R (or Rscript) that
>> standard output should be unbuffered, even if it is not directly
>> connected to a terminal?

> Use explicit print statements, e.g.  print(a <- 1)

Yes, I noticed that "print" statements get written.  But I wanted the
mere "echo" trace of the execution of the script to be synchronous (as
some statements take many seconds to compute, which I symbolically
replaced by "Sys.sleep" above).

> Littler5D actually won't show anything unless you explicitly call
> cat() or print(), but then it does [...]

It shares the limitation of Rscript, then.

> Littler is an 'all-in' binary and starts and runs demonstrably faster
> than Rscript.

I'm not familiar with Littler.  Speedwise, Rscript is OK for me so far,
as most time is spent within R computations, not much in language
compilation or script interpretation.

> [...] the rather petty refusal of Rscript's main author to a least
> give a reference to littler in Rscript's documentation, let alone
> credit as 'we were there first', [...]

I've long been in academic circles (and elsewhere too), so I'm familiar
with the need of recognizing authorship and people's works.  However,
perusing R mailing list archives, and following actual list contents,
I'm sometimes surprised, and even a bit annoyed, by the recurrent starve
for credit I observe.  Of course, maintainers and contributors much
deserve our thanks and, without going into arguments about what is due
to whom, I think contributors receive praise on average, would it be
only by all the interest shown by the community.  However, it gets a bit
muddy when maintainers or contributors show bad temper when not
receiving the systematic credit they would like to read.

Cicero's friends were telling him how upset they felt that there was
still no statute of Cicero on the public place.  Cicero replied that he
much preferred to hear people saying "Why no Cicero statute yet?" than
to hear people saying "Why the Cicero statute?".  A wise attitude! :-)

--
François Pinard   http://pinard.progiciels-bpi.ca

______________________________________________
[hidden email] 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.