[Rd] timeSeries and optional S4 slots?
Question on timeSeries and S4 classes: Consider the following: library(timeSeries) data <- rnorm(5) treg <- ts(data, frequency=4) t1 <- timeSeries(data, as.Date('2010-04-15') + 1:5) t2 <- as.timeSeries(treg) Now both t1 and t2 are timeSeries objects, yet t...@ts is a valid slot, while t...@ts is not. Thus the ts slot is optional. Sorry if I am misunderstanding the way S4 classes work, but shouldn't a class have a well-defined set of slots? It appears that the "constructor" as.timeSeries() used to create t2 results in a different kind of object from the one used to define t1, yet the class() operator returns the same class name ('timeSeries') in both cases. Thanks, Dominick __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Bug in memDecompress()
Dear R developers, I have discovered a bug in the implementation of lzma decompression in memDecompress(). It is only triggered if the uncompressed size of the content is more than 3 times as large as the compressed content. Here's a simple example to reproduce it: n <- 200 char <- paste(replicate(n, "1234567890"), collapse="") char.comp <- memCompress(char, type="xz") char.dec <- memDecompress(char.comp, type="xz", asChar=TRUE) nchar(char.dec) == nchar(char) raw <- serialize(char, connection=NULL) raw.comp <- memCompress(raw, type="xz") raw.dec <- memDecompress(raw.comp, type="xz") length(raw.dec) == length(raw) char.uns <- unserialize(raw.dec) The root cause seems to be, that lzma_code() will return LZMA_OK even if it could not decompress the whole content. In this case strm.avail_in will be greater than zero. The following patch changes the respective if statements: http://www.statistik.tu-dortmund.de/~olafm/temp/memdecompress.patch It also contains a small fix from the xz upstream for an uninitialized field in lzma_stream. Cheers, Olaf __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Bug in R -e "command"
On 7 May 2010 at 15:23, Sklyar, Oleg (London) wrote: | Hi all: | | since about a month we encountered a problem with R -e command: spaces | in the "command" of R -e "command" are no more tolerated. This same | issue affects 2.11 patched (05-05-2010), 2.10.1, and current devel (at | least the one of two weeks ago). | | (I skip the mid of the printouts, replaced with ...) | | * R -e "message('aaa aaa')" | ARGUMENT 'aaa')' __ignored__ Isn't that a shell quoting issue? I tend to keep the apostrophe on the outside and the double-quote on the inside: e...@ron:~> R --slave -e 'message("aaa aaa")' aaa aaa e...@ron:~> r -e 'message("aaa aaa")' aaa aaa e...@ron:~> Rscript -e 'message("aaa aaa")' aaa aaa but also note e...@ron:~> R --slave -e "message(\"aaa aaa\")" aaa aaa e...@ron:~> R --slave -e "message('aaa aaa')" aaa aaa e...@ron:~> so I can't even replicate your issue. What what it's worth, the cut&paste above came from M-x shell inside Emacs. e...@ron:~> dpkg -l r-base-core littler bash emacs23 | tail -4 ii bash 4.1-3 The GNU Bourne Again SHell ii emacs2323.1+1-5 The GNU Emacs editor (with GTK+ user interfa ii littler0.1.3-1GNU R scripting and command-line front-end ii r-base-core2.11.0-1 GNU R core of statistical computation and gr e...@ron:~> | | | R version 2.11.0 Patched (2010-05-05 r51914) | Copyright (C) 2010 The R Foundation for Statistical Computing | ... | | > message('aaa | + | + | | * /releases/R/2.10/bin/R -e "message('aaa aaa')" | ARGUMENT 'aaa')' __ignored__ | | | R version 2.10.1 Patched (2010-03-27 r51474) | Copyright (C) 2010 The R Foundation for Statistical Computing | ... | | > message('aaa | + | + | | WORKING OLD VERSION: | | * /share/R/20090611/bin/R -e "message('aaa aaa')" | | R version 2.9.0 (2009-04-17) | Copyright (C) 2009 The R Foundation for Statistical Computing | ... | | > message('aaa aaa') | aaa aaa | > | > | | | Dr Oleg Sklyar | Research Technologist | AHL / Man Investments Ltd | +44 (0)20 7144 3803 | oskl...@maninvestments.comno more | | ** | Please consider the environment before printing this email or its attachments. | The contents of this email are for the named addressees ...{{dropped:19}} | | __ | R-devel@r-project.org mailing list | https://stat.ethz.ch/mailman/listinfo/r-devel -- Regards, Dirk __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Bug in R -e "command"
Hi all: since about a month we encountered a problem with R -e command: spaces in the "command" of R -e "command" are no more tolerated. This same issue affects 2.11 patched (05-05-2010), 2.10.1, and current devel (at least the one of two weeks ago). (I skip the mid of the printouts, replaced with ...) * R -e "message('aaa aaa')" ARGUMENT 'aaa')' __ignored__ R version 2.11.0 Patched (2010-05-05 r51914) Copyright (C) 2010 The R Foundation for Statistical Computing ... > message('aaa + + * /releases/R/2.10/bin/R -e "message('aaa aaa')" ARGUMENT 'aaa')' __ignored__ R version 2.10.1 Patched (2010-03-27 r51474) Copyright (C) 2010 The R Foundation for Statistical Computing ... > message('aaa + + WORKING OLD VERSION: * /share/R/20090611/bin/R -e "message('aaa aaa')" R version 2.9.0 (2009-04-17) Copyright (C) 2009 The R Foundation for Statistical Computing ... > message('aaa aaa') aaa aaa > > Dr Oleg Sklyar Research Technologist AHL / Man Investments Ltd +44 (0)20 7144 3803 oskl...@maninvestments.comno more ** Please consider the environment before printing this email or its attachments. The contents of this email are for the named addressees ...{{dropped:19}} __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] A fix that for 'bquote' that may work (PR#14031)
--- On Fri, 6/11/09, tlum...@u.washington.edu wrote: > From: tlum...@u.washington.edu > Subject: Re: [Rd] A fix that for 'bquote' that may work (PR#14031) > To: suharto_angg...@yahoo.com > Cc: r-de...@stat.math.ethz.ch, r-b...@r-project.org > Date: Friday, 6 November, 2009, 11:42 PM > On Thu, 5 Nov 2009, suharto_angg...@yahoo.com > wrote: > > > This is a fix for 'bquote' that may work. > > > > function (expr, where =3D parent.frame())=20 > > { > > unquote <- function(e) { > > if (length(e) <=3D 1 || > !is.language(e))=20 > > e > > else if (e[[1]] =3D=3D > as.name("."))=20 > > eval(e[[2]], > where) > > else as.call(lapply(e, > unquote)) > > } > > unquote(substitute(expr)) > > } > > If you want to use bquote() on function definitions a > better fix is > > bquote <- function (expr, where = parent.frame()) > { > unquote <- function(e) { > if (length(e) <= 1) > e > else if (e[[1]] == > as.name(".")) > eval(e[[2]], > where) > else if (is.pairlist(e)){ > > as.pairlist(lapply(e,unquote)) > } > else as.call(lapply(e, > unquote)) > } > unquote(substitute(expr)) > } > > since that now allows substitution into default arguments, > eg > default<-1 > g<-b2quote(function(x,y=.(default)) x+y ) > > > > -thomas > > Thomas Lumley > Assoc. Professor, Biostatistics > tlum...@u.washington.edu > University of Washington, Seattle > > Thank you. I have tried R 2.11.0. I see that the above is the definition of 'bquote' in R 2.11.0. With the definition, 'bquote' does not substitute into default argument for function with one argument. > default <- 1 > bquote( function(y = .(default)) y ) function(y = .(default)) y > sessionInfo() R version 2.11.0 (2010-04-22) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base To make it also work for function with one argument, in the function 'unquote' in 'bquote', apparently is.pairlist(e) should be the first to be checked, before checking (length(e) <= 1), for example with this definition for 'bquote'. function (expr, where = parent.frame()) { unquote <- function(e) if (is.pairlist(e)) as.pairlist(lapply(e, unquote)) else if (length(e) <= 1L) e else if (e[[1L]] == as.name(".")) eval(e[[2L]], where) else as.call(lapply(e, unquote)) unquote(substitute(expr)) } There is a cosmetic problem if 'bquote' is applied to function definition with more than one line. > fq <- bquote( + function() { + } + ) > f <- eval(fq) > str(f) function () - attr(*, "source")= language ... The "source" attribute of the 'eval'-ed function is a language object. Normally, "source" attribute of a function is character. One way to avoid that is by not changing non-call object (except pairlist) in 'unquote', for example by using this definition for 'bquote'. function (expr, where = parent.frame()) { unquote <- function(e) if (is.pairlist(e)) as.pairlist(lapply(e, unquote)) else if (!is.call(e)) e else if (e[[1L]] == as.name(".") && length(e) > 1L) eval(e[[2L]], where) else as.call(lapply(e, unquote)) unquote(substitute(expr)) } The logic of 'unquote' above can be written like this. - Check if 'e' is a call object. - If 'e' is not a call object, leave it as is, except if it is a pairlist. - If 'e' is a call object, check if it is a call to '.' with argument. If yes, 'eval' its (first) argument. If not, 'unquote' its parts. I assume that length of a call object is at least 1. In my last definition above for 'unquote' in 'bquote', call object of length 1 is not special-cased. That will allow 'bquote' to substitute to function name for a call to function without argument. Currently, substitution to function name only works for a call to function with argument. > bquote function (expr, where = parent.frame()) { unquote <- function(e) if (length(e) <= 1L) e else if (e[[1L]] == as.name(".")) eval(e[[2L]], where) else if (is.pairlist(e)) as.pairlist(lapply(e, unquote)) else as.call(lapply(e, unquote)) unquote(substitute(expr)) } > fnam <- as.name("f") > bquote( .(fnam)() ) .(fnam)() > bquote( .(fnam)(x) ) f(x) __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel