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\""
>> "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.

vQ

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


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
>>  http://www.neurofractal.org/felix/
>>  3358 543D AAC6 22C2 D336 80D9 360B 72DD 3E4C F5D8

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


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

2008-07-24 Thread Henrik Bengtsson
Hi,

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.

Example:
x <- 1:1e7;
t1 <- system.time(raw1 <- serialize(x, connection=NULL));
print(t1);
#user  system elapsed
#   174.23  129.35  304.70  ## 5 minutes
t2 <- system.time(raw2 <- serialize2(x, connection=NULL));
print(t2);
# user  system elapsed
# 2.190.185.72  ## 5 seconds
print(t1/t2);
#  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");
on.exit({
  if (!is.null(con))
close(con);
  if (file.exists(pathname))
file.remove(pathname);
});
base::serialize(object, connection=con, ...);
close(con);
con <- NULL;
fileSize <- file.info(pathname)$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:

> sessionInfo()
R version 2.7.1 Patched (2008-06-27 r46012)
i386-pc-mingw32

locale:
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:

> sessionInfo()
R version 2.7.1 (2008-06-23)
x86_64-unknown-linux-gnu

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

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

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

Cheers

Henrik

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] How to loop through a set of data and to evaluate a function?

2008-07-24 Thread NicoNYC

Hi,
I will explain my problem :
I would like to loop through a set of data taking the set 100 points at a
time.  At each iteration I'd like to evaluate a function over this set.  In
each subsequent iteration i add the next point to my sub set and remove the
oldest and evaluate the function again (something like a moving window).

Small example : this is my data:
1
2
3
..
10

with a moving window of 3 points, i would like to evaluate the following
f(1,2,3)
f(2,3,4)
f(3.4.5)
...
f(8,9,10)

Thank you!
-- 
View this message in context: 
http://www.nabble.com/How-to-loop-through-a-set-of-data-and-to-evaluate-a-function--tp18633260p18633260.html
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel