[R] shQuote and cat

2008-07-23 Thread Vadim Organovich
Dear R-users,

It is my understanding that cat(shQuote(a.string)) should print the origintal 
a.string. Is this right?
I am not sure cat() correctly prints strings which are generated by 
triple-shQuote():

> shQuote(shQuote("a"))
[1] "\"\\\"a\\\"\""
> cat(shQuote(shQuote(shQuote("a"))), '\n')
"\"\\"a\\"\""
As you can see the latter string has fewer quoting '\' than the former.
cat() of double shQuote works as expected:

> shQuote("a")
[1] "\"a\""
> cat(shQuote(shQuote("a")), '\n')
"\"a\""
> version
   _
platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status
major  2
minor  6.1
year   2007
month  11
day26
svn rev43537
language   R
version.string R version 2.6.1 (2007-11-26)
Am I missing something?

Thanks,
Vadim


Note: This email is for the confidential use of the named addressee(s) only and 
may contain proprietary, confidential or privileged information. If you are not 
the intended recipient, you are hereby notified that any review, dissemination 
or copying of this email is strictly prohibited, and to please notify the 
sender immediately and destroy this email and any attachments. Email 
transmission cannot be guaranteed to be secure or error-free. Jump Trading, 
therefore, does not make any guarantees as to the completeness or accuracy of 
this email or any attachments. This email is for informational purposes only 
and does not constitute a recommendation, offer, request or solicitation of any 
kind to buy, sell, subscribe, redeem or perform any type of transaction of a 
financial product.

[[alternative HTML version deleted]]

__
R-help@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.


[R] operating on arrays of unknown dimensionality

2008-08-08 Thread Vadim Organovich
Dear R-users,

I am looking for a way to assign to slices of arrays where dimensionality of 
the array is not a-priory known.

Specifically, I would like to be able to generalize the following example of 
dimensionality 2 to an arbitrary diminsionality:

In this example we create an array x, a smaller array y and then assign y to a 
slice of x.

> dimnmx <- list(c('a','b'), c('x','y','z')); x <- array(0, dim=sapply(dimnmx, 
> length), dimnames=dimnmx)
> x
  x y z
a 0 0 0
b 0 0 0
> dimnmy <- list(c('a','b'), c('x','z')); y <- array(1, dim=sapply(dimnmy, 
> length), dimnames=dimnmy)
> y
  x z
a 1 1
b 1 1
> x[dimnames(y)[[1]], dimnames(y)[[2]]] <- y
> x
  x y z
a 1 0 1
b 1 0 1


Now suppose I have an arbitrary lists dimnmx and dimnmy which are dimnames of 
respective arrays y and x. How do I assign y to the slice of x sliced out by 
dimnmy:

> dimnmx <- list(c('a','b'), c('x','y','z'), c('1','2')); x <- array(0, 
> dim=sapply(dimnmx, length), dimnames=dimnmx)
> dimnmy <- list(c('a','b'), c('x','z'), c('2')); y <- array(1, 
> dim=sapply(dimnmy, length), dimnames=dimnmy)
> something to the effect of do.call('[', list(x, dimnames(y))) <- y

Thanks,
Vadim

Note: This email is for the confidential use of the named addressee(s) only and 
may contain proprietary, confidential or privileged information. If you are not 
the intended recipient, you are hereby notified that any review, dissemination 
or copying of this email is strictly prohibited, and to please notify the 
sender immediately and destroy this email and any attachments.  Email 
transmission cannot be guaranteed to be secure or error-free.  Jump Trading, 
therefore, does not make any guarantees as to the completeness or accuracy of 
this email or any attachments.  This email is for informational purposes only 
and does not constitute a recommendation, offer, request or solicitation of any 
kind to buy, sell, subscribe, redeem or perform any type of transaction of a 
financial product.

__
R-help@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.


[R] stopifnot message mutation

2008-08-15 Thread Vadim Organovich
Dear R-users,

Could someone please explain why the message printed by function stopifnot2, 
see below, is different from that of stopifnot itself?

Thank you for your help,
Vadim


> stopifnot2 <- function(...) stopifnot(...)
> stopifnot(F)
Error: F is not TRUE
> stopifnot2(F)
Error: ..1 is not TRUE

> version
   _
platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status
major  2
minor  6.1
year   2007
month  11
day26
svn rev43537
language   R
version.string R version 2.6.1 (2007-11-26)

Note: This email is for the confidential use of the named addressee(s) only and 
may contain proprietary, confidential or privileged information. If you are not 
the intended recipient, you are hereby notified that any review, dissemination 
or copying of this email is strictly prohibited, and to please notify the 
sender immediately and destroy this email and any attachments.  Email 
transmission cannot be guaranteed to be secure or error-free.  Jump Trading, 
therefore, does not make any guarantees as to the completeness or accuracy of 
this email or any attachments.  This email is for informational purposes only 
and does not constitute a recommendation, offer, request or solicitation of any 
kind to buy, sell, subscribe, redeem or perform any type of transaction of a 
financial product.

__
R-help@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.


Re: [R] stopifnot message mutation

2008-08-15 Thread Vadim Organovich
Thank you very much Charles!

I probably should stop passing the dots to subfunctions and rather doctor the 
results of as.list(match.call()), e.g.

mc <- as.list(match.call())
mc[[1]] <- stopifnot
eval(as.call(mc))

This looks safer.

Thanks again,
Vadim


From: Charles C. Berry [EMAIL PROTECTED]
Sent: Friday, August 15, 2008 2:27 PM
To: Vadim Organovich
Cc: r-help@r-project.org
Subject: Re: [R] stopifnot message mutation

On Fri, 15 Aug 2008, Vadim Organovich wrote:

> Dear R-users,
>
> Could someone please explain why the message printed by function stopifnot2, 
> see below, is different from that of stopifnot itself?


Refer to the source

page(stopifnot,'print')

Then consider this:

> foo <- function(...) match.call()
> foo2 <- function(...) foo(...)
> foo(a+b)[[2]]
a + b
> foo2(a+b)[[2]]
..1
>


HTH,

Chuck


>
> Thank you for your help,
> Vadim
>
>
>> stopifnot2 <- function(...) stopifnot(...)
>> stopifnot(F)
> Error: F is not TRUE
>> stopifnot2(F)
> Error: ..1 is not TRUE
>
>> version
>   _
> platform   i386-pc-mingw32
> arch   i386
> os mingw32
> system i386, mingw32
> status
> major  2
> minor  6.1
> year   2007
> month  11
> day26
> svn rev43537
> language   R
> version.string R version 2.6.1 (2007-11-26)
>
> Note: This email is for the confidential use of the named addressee(s) only 
> and may contain proprietary, confidential or privileged information. If you 
> are not the intended recipient, you are hereby notified that any review, 
> dissemination or copying of this email is strictly prohibited, and to please 
> notify the sender immediately and destroy this email and any attachments.  
> Email transmission cannot be guaranteed to be secure or error-free.  Jump 
> Trading, therefore, does not make any guarantees as to the completeness or 
> accuracy of this email or any attachments.  This email is for informational 
> purposes only and does not constitute a recommendation, offer, request or 
> solicitation of any kind to buy, sell, subscribe, redeem or perform any type 
> of transaction of a financial product.
>
> __
> R-help@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:[EMAIL PROTECTED]   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

Note: This email is for the confidential use of the named addressee(s) only and 
may contain proprietary, confidential or privileged information. If you are not 
the intended recipient, you are hereby notified that any review, dissemination 
or copying of this email is strictly prohibited, and to please notify the 
sender immediately and destroy this email and any attachments.  Email 
transmission cannot be guaranteed to be secure or error-free.  Jump Trading, 
therefore, does not make any guarantees as to the completeness or accuracy of 
this email or any attachments.  This email is for informational purposes only 
and does not constitute a recommendation, offer, request or solicitation of any 
kind to buy, sell, subscribe, redeem or perform any type of transaction of a 
financial product.

__
R-help@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.


[R] writintg wrappers around save()

2008-03-21 Thread Vadim Organovich
Dear R-users,

I am trying to write a wrapper function around save() that will report the file 
which is being saved to.

So I thought that the followintg would do the trick, but it doesn't. I 
understand that 'y' is somehow not visible inside save.verbose, but don't know 
how to fix this.

save.verbose <- function(..., file) {
  cat("save.verbose:", file, "\n")
  save(..., file=file)
}
> foo <- function(x) { y <- x; save.verbose('y', file='foo.rda') }; foo(1)
save.verbose: foo.rda
Error in save(..., file = file) : object 'y' not found
Any suggestion how to fix this?

Thank you for your time,
Vadim

P.S. I have a nagging feeling that I've already asked this question but I am 
not able to find any trace of it in the archives. My apologiesif this is so.

[[alternative HTML version deleted]]

__
R-help@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.


[R] computing on expressions

2008-10-03 Thread Vadim Organovich
Dear R-users,

Suppose I have an expression:

expr = expression(a>0)

and now I want to modify it to expression(a>0 & b>0). The following doesn't 
work:

expr = expression(expr & b>0)

What would be a good way of doing this?

Thanks,
Vadim


Note: This email is for the confidential use of the named addressee(s) only and 
may contain proprietary, confidential or privileged information. If you are not 
the intended recipient, you are hereby notified that any review, dissemination 
or copying of this email is strictly prohibited, and to please notify the 
sender immediately and destroy this email and any attachments. Email 
transmission cannot be guaranteed to be secure or error-free. Jump Trading, 
therefore, does not make any guarantees as to the completeness or accuracy of 
this email or any attachments. This email is for informational purposes only 
and does not constitute a recommendation, offer, request or solicitation of any 
kind to buy, sell, subscribe, redeem or perform any type of transaction of a 
financial product.

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] computing on expressions

2008-10-03 Thread Vadim Organovich
Thanks!

Here is a less verbose variation based on suggestion by Phil Spector:

parse(text=paste(expression(a>0), "& b>0"))


From: Henrique Dallazuanna [EMAIL PROTECTED]
Sent: Friday, October 03, 2008 11:08 AM
To: Vadim Organovich
Cc: r-help@r-project.org
Subject: Re: [R] computing on expressions

Try this:

parse(text = paste(capture.output(expr[[1]]), " & b > 0"))

On Fri, Oct 3, 2008 at 12:48 PM, Vadim Organovich
<[EMAIL PROTECTED]> wrote:
> Dear R-users,
>
> Suppose I have an expression:
>
> expr = expression(a>0)
>
> and now I want to modify it to expression(a>0 & b>0). The following doesn't 
> work:
>
> expr = expression(expr & b>0)
>
> What would be a good way of doing this?
>
> Thanks,
> Vadim
>
> 
> Note: This email is for the confidential use of the named addressee(s) only 
> and may contain proprietary, confidential or privileged information. If you 
> are not the intended recipient, you are hereby notified that any review, 
> dissemination or copying of this email is strictly prohibited, and to please 
> notify the sender immediately and destroy this email and any attachments. 
> Email transmission cannot be guaranteed to be secure or error-free. Jump 
> Trading, therefore, does not make any guarantees as to the completeness or 
> accuracy of this email or any attachments. This email is for informational 
> purposes only and does not constitute a recommendation, offer, request or 
> solicitation of any kind to buy, sell, subscribe, redeem or perform any type 
> of transaction of a financial product.
>
>[[alternative HTML version deleted]]
>
> __
> R-help@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.
>



--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

Note: This email is for the confidential use of the named addressee(s) only and 
may contain proprietary, confidential or privileged information. If you are not 
the intended recipient, you are hereby notified that any review, dissemination 
or copying of this email is strictly prohibited, and to please notify the 
sender immediately and destroy this email and any attachments.  Email 
transmission cannot be guaranteed to be secure or error-free.  Jump Trading, 
therefore, does not make any guarantees as to the completeness or accuracy of 
this email or any attachments.  This email is for informational purposes only 
and does not constitute a recommendation, offer, request or solicitation of any 
kind to buy, sell, subscribe, redeem or perform any type of transaction of a 
financial product.

__
R-help@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.


[R] making array of lists

2008-03-03 Thread Vadim Organovich
Dear R Users,



Given two vectors, say a = seq(2) and b = seq(3), I want to make an 2*3 array, 
where (i,j) element is list(a=a[i], b=b[j]). I tried the outer() function but 
it generates an error message that I don't understand, see below.



What do I do wrong?



The expan.grid function is not good enough since I need a solution that works 
when a and b are not atomic, say a=list(list(x=1, y=2), list(x=2, y=1)).



Thanks,

Vadim



> a <- seq(2); b <- seq(3)
> outer(a, b, function(a, b) list(a=a, b=b))
Error in dim(robj) <- c(dX, dY) :
  dims [product 6] do not match the length of object [2]





[[alternative HTML version deleted]]

__
R-help@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.