Re: [Rd] [R] shQuote and cat

2008-07-24 Thread Wacek Kusnierczyk
Duncan Murdoch wrote:
 Vadim Organovich wrote:
 It is precizely a shell command that I am trying to generate. To be
 specific let's try to have R 'output' the following shell command:
 'echo \a\'. This is is a valid command, at least in bash:
 bash-3.2$ echo \a\

 Now in R:
 x - 'echo \a\'
 cat(x, '\n')
 echo a
 cat(shQuote(x), '\n')
 echo \\a\\

 Whichever way you do it it is not right. Again I think cat('echo
 \a\') should be printing *echo \a\* (asterics are not a part
 of the output)
try this:

(x = 'echo \\a\\') # or x = 'echo a')
[1] echo a

cat(x, \n)
# echo \a\

as desired.  you need to backslash the backslash.


__ mailing list

Re: [Rd] plot.dendrogram xlim/ylim

2008-07-24 Thread Martin Maechler
 FA == Felix Andrews [EMAIL PROTECTED]
 on Thu, 24 Jul 2008 13:16:22 +1000 writes:

FA list(...), I would like to zoom in to the leaves of
FA large trees in a dendrogram plot. The playwith package
FA allows zooming by passing xlim and ylim arguments to the
FA plot call (Hmisc does this too I think). But currently
FA stats:::plot.dendrogram does not accept xlim or ylim. So
FA I would like to enable that. In place of the existing
FA code chunk:

   xlim - c(x1 - 1/2, x2 + 1/2)
   ylim - c(0, yTop)
   if (horiz) {
   xl - xlim
   xlim - rev(ylim)
   ylim - xl
   tmp - xaxt
   xaxt - yaxt
   yaxt - tmp
   plot(0, xlim = xlim, ylim = ylim, ..
   I propose something like:
   function(..., xlim, ylim)
   xlim0 - c(x1 - 1/2, x2 + 1/2)
   ylim0 - c(0, yTop)
   if (horiz) {
   xl - xlim0
   xlim0 - rev(ylim0)
   ylim - xl
   tmp - xaxt
   xaxt - yaxt
   yaxt - tmp
   if (missing(xlim)) xlim - xlim0
   if (missing(ylim)) ylim - ylim0
   plot(0, xlim = xlim, ylim = ylim, ..

Thank you for the suggestion!
Yes, something like this will be part of R 2.8.0
(or 'R-devel' as from tomorrow).

Martin Maechler, ETH Zurich

  Felix Andrews / 安福立
  PhD candidate
  Integrated Catchment Assessment and Management Centre
  The Fenner School of Environment and Society
  The Australian National University (Building 48A), ACT 0200
  Beijing Bag, Locked Bag 40, Kingston ACT 2604
  3358 543D AAC6 22C2 D336 80D9 360B 72DD 3E4C F5D8

__ mailing list

[Rd] serialize() to via temporary file is heaps faster than doing it directly (on Windows)

2008-07-24 Thread Henrik Bengtsson

FYI, I just notice that on Windows (but not Linux) it is orders of
magnitude (below it's 50x) faster to serialize() and object to a
temporary file and then read it back, than to serialize to an object
directly.  This has for instance impact on how fast digest::digest()
can provide a checksum.

x - 1:1e7;
t1 - system.time(raw1 - serialize(x, connection=NULL));
#user  system elapsed
#   174.23  129.35  304.70  ## 5 minutes
t2 - system.time(raw2 - serialize2(x, connection=NULL));
# user  system elapsed
#  ## 5 seconds
#  usersystem   elapsed
#   79.55708 718.6  53.26923
stopifnot(identical(raw1, raw2));

where serialize2() is serialize():ing to file and reading the results back:

serialize2 - function(object, connection, ...) {
  if (is.null(connection)) {
# It is faster to serialize to a temporary file and read it back
pathname - tempfile();
con - file(pathname, open=wb);
  if (!is.null(con))
  if (file.exists(pathname))
base::serialize(object, connection=con, ...);
con - NULL;
fileSize -$size;
readBin(pathname, what=raw, n=fileSize);
  } else {
base::serialize(object, connection=connection, ...);
} # serialize2()

The above benchmarking was done in a fresh R v2.7.1 session on WinXP Pro:

R version 2.7.1 Patched (2008-06-27 r46012)

LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MON
ETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

When I do the same on a Linux machine there is no difference:

R version 2.7.1 (2008-06-23)


attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

Is there an obvious reason (and an obvious fix) for this?



__ mailing list