[Rd] Bug: broken exception handling in S4 methods

2010-07-21 Thread Sklyar, Oleg (London)
Hi all:

we have noticed for quite a while that certain errors cannot be handled
by R try, tryCatch etc blocks, but it was fairly difficult to understand
what were the conditions for this incorrect behaviour. Finally I stabbed
across a very understandable case, which is outlined in the (runnable)
example below. 

The main message is: wrapping an S4 method call in a try block will not
help if an error occurs in evaluating an argument to such a call; this
works just fine for function calls (as opposed to S4 methods)

The particular example is a result of trying to write a unit test for a
constructor of a class object which should fail under certain
conditions. This failure obviously need to be caught for the unit test
to proceed. However, it is a general problem with handling some
exceptions in R.

# Consider a simple class MyClassA, which is derived from numeric and
for which 
# we define a constructor (in form of a method). On its own this class
works nicely 
# and so does exception handling of it:

setClass(MyClassA,
contains = numeric,
validity = function(object)
{
stopifnot(object[1] == object[2])
TRUE
}
)


setGeneric(MyClassA, function(x) standardGeneric(MyClassA))

setMethod(MyClassA,
signature(x = numeric),
function(x)
{
new(MyClassA, x)
}
)

## OK
er = try({ MyClassA(c(1,2)) })

## OK (error in constructor)
er = try({ MyClassA(c(1,2)) })

## OK (error evaluating argument to a function)
er = try({ sin(MyClassA(c(1,2))) })


# Now consider we define MyClassB that has MyClassA in a slot 
# and we define a constructor that takes such objects:


setClassUnion(MyClassAOrNULL, c(MyClassA, NULL))

setClass(MyClassB,
representation(
ca = MyClassAOrNULL
),
prototype(ca = NULL)
)

setGeneric(MyClassB, function(x) standardGeneric(MyClassB))

setMethod(MyClassB,
signature(x = MyClassA),
function(x)
{
new(MyClassB, ca = x)
}
)

## OK
b = MyClassB(MyClassA(c(1,1)))

## FAILS (error evaluating argument to a method)
er = try({ MyClassB(MyClassA(c(1,2))) })

# As you see the last error cannot be handled


# Moreover. If we define a function and a method as function(x) x then 
# the function can be handled by try, yet the method cannot:

f = function(x) x

setGeneric(g, function(x) standardGeneric(g))
setMethod(g, MyClassA, function(x) x)

## OK (error evaluating argument to a function)
er = try({ f(MyClassA(c(1,2))) })

## FAILS (error evaluating argument to a method)
er = try({ g(MyClassA(c(1,2))) })



 sessionInfo()
R version 2.11.0 Patched (2010-05-05 r51914) 
x86_64-unknown-linux-gnu 

locale:
 [1] LC_CTYPE=en_GB   LC_NUMERIC=C LC_TIME=en_GB
LC_COLLATE=en_GB
 [5] LC_MONETARY=CLC_MESSAGES=en_GBLC_PAPER=en_GB
LC_NAME=C   
 [9] LC_ADDRESS=C LC_TELEPHONE=C   LC_MEASUREMENT=en_GB
LC_IDENTIFICATION=C 

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


Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3803
oskl...@ahl.com

**
 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] POSIXlt matching bug

2010-07-02 Thread Sklyar, Oleg (London)
POSIXlt is a list and it is not a list of dates or times, it is a list
of 

 x - as.POSIXlt(Sys.Date())
 names(x)
[1] sec   min   hour  mday  mon   year  wday  yday
isdst

So if you want to match these things, you should use POSIXct or any
other numeric-based format (as POSIXct is just a double value for the
number of seconds since 1970-01-01) e.g.

 z - as.POSIXct(Sys.Date())
 x - as.POSIXct(Sys.Date())
 z==x
[1] TRUE
 match(z,x)
[1] 1
 z %in% x
[1] TRUE

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3803
oskl...@maninvestments.com 

 -Original Message-
 From: r-devel-boun...@r-project.org 
 [mailto:r-devel-boun...@r-project.org] On Behalf Of McGehee, Robert
 Sent: 29 June 2010 15:46
 To: r-b...@r-project.org; r-devel@r-project.org
 Subject: [Rd] POSIXlt matching bug
 
 I came across the below mis-feature/bug using match with 
 POSIXlt objects
 (from strptime) in R 2.11.1 (though this appears to be an old issue).
 
  x - as.POSIXlt(Sys.Date())
  table - as.POSIXlt(Sys.Date()+0:5)
  length(x)
 [1] 1
  x %in% table  # I expect TRUE
 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
  match(x, table) # I expect 1
 [1] NA NA NA NA NA NA NA NA NA
 
 This behavior seemed more plausible when the length of a 
 POSIXlt object
 was 9 (back in the day), however since the length was redefined, the
 length of x no longer matches the length of the match function output,
 as specified by the ?match documentation: A vector of the same length
 as 'x'.
 
 I would normally suggest that we add a POSIXlt method for match that
 converts x into POSIXct or character first. However, match does not
 appear to be generic. Below is a possible rewrite of match 
 that appears
 to work as desired.
 
 match - function(x, table, nomatch = NA_integer_, 
 incomparables = NULL)
 
 .Internal(match(if(is.factor(x)||inherits(x, POSIXlt))
 as.character(x) else x,
 if(is.factor(table)||inherits(table, POSIXlt))
 as.character(table) else table,
 nomatch, incomparables))
 
 That said, I understand some people may be very sensitive to the speed
 of the match function, and may prefer a simple change to the ?match
 documentation noting this (odd) behavior for POSIXlt. 
 
 Thanks, Robert
 
 R.version
_
 platform   x86_64-unknown-linux-gnu 
 arch   x86_64   
 os linux-gnu
 system x86_64, linux-gnu
 status  
 major  2
 minor  11.1 
 year   2010 
 month  05   
 day31   
 svn rev52157
 language   R
 version.string R version 2.11.1 (2010-05-31)
 
 Robert McGehee, CFA
 Geode Capital Management, LLC
 One Post Office Square, 28th Floor | Boston, MA | 02109
 Tel: 617/392-8396Fax:617/476-6389
 mailto:robert.mcge...@geodecapital.com
 
 
 This e-mail, and any attachments hereto, are intended for use by the
 addressee(s) only and may contain information that is (i) confidential
 information of Geode Capital Management, LLC and/or its affiliates,
 and/or (ii) proprietary information of Geode Capital Management, LLC
 and/or its affiliates. If you are not the intended recipient of this
 e-mail, or if you have otherwise received this e-mail in error, please
 immediately notify me by telephone (you may call collect), or 
 by e-mail,
 and please permanently delete the original, any print outs and any
 copies of the foregoing. Any dissemination, distribution or copying of
 this e-mail is strictly prohibited. 
 
 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel
 

**
 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] Bug in R -e command

2010-05-10 Thread Sklyar, Oleg (London)
Hi Dirk, all:

your answer prompted me to look in another place, and yes I need to
withdraw the bug report: it was a problem on our side.

Thanks,
Oleg


Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3803
oskl...@maninvestments.com 

 -Original Message-
 From: Dirk Eddelbuettel [mailto:e...@debian.org] 
 Sent: 07 May 2010 15:43
 To: Sklyar, Oleg (London)
 Cc: r-devel@r-project.org
 Subject: 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 cutpaste
 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
 

**
 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


[Rd] Bug in R -e command

2010-05-07 Thread Sklyar, Oleg (London)
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] Why no race condition when returning UNPROTECT-ed memory fromC?

2010-04-14 Thread Sklyar, Oleg (London)
Because there is no second thread to do that, R is single threaded. The
gc could only be run from within another R API command or macro, but
there is none in between.

Best
Oleg

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3803
oskl...@maninvestments.com 

 -Original Message-
 From: r-devel-boun...@r-project.org 
 [mailto:r-devel-boun...@r-project.org] On Behalf Of Dominick Samperi
 Sent: 14 April 2010 06:51
 To: r-devel@r-project.org
 Subject: [Rd] Why no race condition when returning 
 UNPROTECT-ed memory fromC?
 
 Consider the C (or C++) code called from the .Call interface:
 SEXP foo() {
   SEXP *p = PROTECT(allocVector(REALSXP, 10));
   ...
   UNPROTECT(1);
   return p;
 }
 
 Why is there no danger that the allocated memory will be garbage
 collected after the UNPROTECT, but before the return of p?
 
 I have used code like this for some time and have never had a
 problem, but I'm not sure if/why it is guaranteed to work.
 
 Thanks,
 Dominick
 
   [[alternative HTML version deleted]]
 
 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel
 

**
 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


[Rd] Job: AHL Research Developer, R/python - top hedge fund, Oxford/London UK

2010-04-13 Thread Sklyar, Oleg (London)
Dear list subscribers,

this is posted in appreciation of the level of skill that subscribers to this 
mailing list enjoy and in no way to abuse it.

We are looking to hire a Research Developer with extensive R and/or python 
development skills. If interested (below), please contact me directly on 
oskl...@ahl.com:

Man Group / AHL Research Developer [3040]

Man is a world-leading alternative investment management business. With a broad 
range of funds for institutional and private investors globally, it is known 
for its performance, innovative product design and investor service.  Man's 
funds under management at the end of year 2009 were roughly at $42 billion.

The original business was founded in 1783. Today, Man Group plc is listed on 
the London Stock Exchange and is a member of the FTSE 100 Index with a market 
capitalisation of around £4 billion.

Within Man AHL is a world-leading quantitative investment manager with an 
extensive history of performance and innovation. A pioneer in the application 
of systematic trading, we have been serving institutional and private clients 
since 1987. Further information can be found at www.ahl.com.

As part of its investment in quantitative finance research, Man Group and its 
quantitative investment manager AHL have established a Research Laboratory at 
Oxford. The Laboratory is sharing the same offices with the Oxford-Man 
Institute of Quantitative Finance encouraging interaction between academic and 
commercial researchers. It pursues commercially driven research programmes 
primarily focussed on the needs of AHL but collaborates with the Institute 
through seminars, workshops and informal discussions.

In our research we facilitate the use of the tools that are widely spread 
throughout the academic quantitative and statistical computing landscape, like 
Python and R. There is an immediate and on-going need to develop advanced and 
technologically modern computational tools and quantitative techniques to 
support the AHL research programmes. In addition, there are a number of 
potentially applicable Information Systems and Information Engineering academic 
research programmes, which require commercial evaluation and assessment.

Working in close cooperation with the AHL Research teams, both in Oxford and 
London, and the AHL Technology group in London, the successful candidate will 
design, develop and implement necessary software libraries and frameworks in R, 
Python and other languages to support the Oxford research team in technology 
topics and develop recommendations on the use of software configuration 
management in the AHL research projects.

Responsibilities:

- Design and develop software libraries and frameworks in R and Python to 
support the Laboratory's research activities and write corresponding 
documentation and example code

- Work with the AHL Technology and AHL Research teams to develop interfaces 
between various platforms, in particular Java, C/C++, R and Python to 
facilitate effective data and information exchange 

- Provide assistance, support and seminars to the researchers on the optimal 
use of R and Python libraries and Linux 

- Propose and implement algorithms to assist in data analysis tasks 

- Develop recommendations for the use of R and Python in research projects, 
code reuse and configuration management across the Laboratory and with the AHL 
Research technology to ensure maximum productivity 

- Collaborate with the Institute's computer science research team as required 
and keep up to date with the computer science research being undertaken at the 
Institute and in related University departments 

- Work with the AHL Technology Group to ensure that the technology experience 
and facilities at the Laboratory are fit for purpose 

- Act as the point of contact between the Oxford research staff and the London 
based AHL Technology group 

Requirements:

- PhD or experienced MSc/Part III in quantitative research in maths, science, 
engineering or computer science 

- Fluent R or Python and at least one of C, C++, or Java; confidence with 
Linux, Unix or similar 

- Mathematical skills to 1st year post-graduate and excellent analytical skills 

- Experience in statistical analysis and modelling, optimisation algorithms, 
data visualisation, preferably with relation to large data sets 

- Passion for computer science and statistics and its application to financial 
markets 

- Good communication and team working skills coupled with capability for 
innovative thinking 

Advantageous

- Knowledge of object oriented design, distributed computing, relational 
databases 

- Experience working with Beowulf-style Linux clusters, MPI, slurm, condor etc 

- Experience of software development in a dealer/trading desk environment 

Man Group, and all related entities, is an equal opportunity employer through 
the application of a policy of non-discrimination on the grounds of sex, 
marital or civil partner status, gender 

[Rd] likely bug in 'serialize' or please explain the memory usage

2009-11-03 Thread Sklyar, Oleg (London)
Hi all,

assume the following problem: a function call takes a function object
and a data variable and calls this function with this data on a remote
host. It uses serialization to pass both the function and the data via a
socket connection to a remote host. The problem is that depending on the
way we call the same construct, the function may be serialized to
include the data, which was not requested as the example below
demonstrates (runnable). This is a problem for parallel computing. The
problem described below is actually a problem for Rmpi and any other
parallel implementation we tested leading to endless executions in some
cases, where the total data passed is huge.

Assume the below 'mycall' is the function that takes data and a function
object, serializes them and calls the remote host. To make it runable I
just print the size of the serialized objects. In a parallel apply
implemention it would serialize individual list elements and a function
and pass those over. Assuming 1 element is 1Mb and having 100 elements
and a function as simple as function(z) z we would expect to pass around
100Mb of data, 1 Mb to each individual process. However what happens is
that in some situations all 100Mb of data are passed to all the slaves
as the function is serialized to include all of the data! This always
happens when we make such a call from an S4 method when the function we
is defined inline, see last example. 

Anybody can explain this, and possibly suggest a solution? Well, one is
-- do not define functions to call in the same environment as the caller
:(

I do not have immediate access to the newest version of R, so would be
grateful if sombody could test it in that and let me know if the problem
is still there. The example is runnable.

Thanks,
Oleg

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3803
oskl...@maninvestments.com


---

mycall = function(x, fun) {
FUN = serialize(fun, NULL)
DAT = serialize(x, NULL)

cat(sprintf(length FUN=%d; length DAT=%d\n, length(FUN),
length(DAT)))
invisible(NULL) ## return results of a call on a remote host with
FUN and DAN
}

## the function variant I  will be passing into mycall
innerfun = function(z) z
x = runif(1e6)

## test run from the command line
mycall(x, innerfun)
# output: length FUN=106; length DAT=822

## test run from within a function
outerfun1 = function(x) mycall(x, innerfun)
outerfun1(x)
# output: length FUN=106; length DAT=822

## test run from within a function, where function is defined within
outerfun2 = function(x) {
nestedfun = function(z) z
mycall(x, nestedfun)
}
outerfun2(x)
# output: length FUN=253; length DAT=822

setGeneric(outerfun3, function(x) standardGeneric(outerfun3))
## define a method

## test run from within a method
setMethod(outerfun3, numeric,
function(x) mycall(x, innerfun))
outerfun3(x)
# output@ length FUN=106; length DAT=822

## test run from within a method, where function is defined within
setMethod(outerfun3, numeric,
function(x) {
nestedfun = function(z) z
mycall(x, nestedfun)
})
## THIS WILL BE WRONG!
outerfun3(x)
# output: length FUN=8001680; length DAT=822


--
R version 2.9.0 (2009-04-17) 
x86_64-unknown-linux-gnu 

locale:
C

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


**
 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] likely bug in 'serialize' or please explain the memory usage

2009-11-03 Thread Sklyar, Oleg (London)
Duncan,

thanks for suggestions, I will try attaching a new environment.

However this still does not explain the behaviour and does not confirm
that it is correct. What puzzles me most is that if I define a function
within another function then only the function gets serialized, yet when
this is withing an S4 method definition, then also the args. Both have
their own environments, so I do not see why it should be different. As
an interim measure I just removed all the inline function definitions
from these 'parallel' calls defining the functions as hidden outside of
the caller, a bit ugly but works. I'd be thankful if you could look at
the examples when you get some more time.

My main problem is less in ensuring that my code works, but in ensuring
that when users use these parallel functionalities with their code, they
do not get stuck in transferring data for ages simply because with every
function one gets all the data passed.

Best,
Oleg

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3803
oskl...@maninvestments.com 

 -Original Message-
 From: Duncan Murdoch [mailto:murd...@stats.uwo.ca] 
 Sent: 03 November 2009 11:59
 To: Sklyar, Oleg (London)
 Cc: r-devel@r-project.org
 Subject: Re: [Rd] likely bug in 'serialize' or please explain 
 the memory usage
 
 I haven't had a chance to look really closely at this, but I 
 would guess 
 the problem is that in R functions are closures.  The environment 
 attached to the function will be serialized along with it, so if you 
 have a big dataset in the same environment, you'll get that too.
 
 I vaguely recall that the global environment and other system 
 environments are handled specially, so that's not true for functions 
 created at the top level, but I'd have to do some experiments 
 to confirm.
 
 So the solution to your problem is to pay attention to the 
 environment 
 of the functions you create.  If they need to refer to local 
 variables 
 in the creating frame, then
 you'll get all of them, so be careful about what you create 
 there.  If 
 they don't need to refer to the local frame you can just attach a new 
 smaller environment after building the function.
 
 Duncan Murdoch
 
 Sklyar, Oleg (London) wrote:
  Hi all,
 
  assume the following problem: a function call takes a 
 function object
  and a data variable and calls this function with this data 
 on a remote
  host. It uses serialization to pass both the function and 
 the data via a
  socket connection to a remote host. The problem is that 
 depending on the
  way we call the same construct, the function may be serialized to
  include the data, which was not requested as the example below
  demonstrates (runnable). This is a problem for parallel 
 computing. The
  problem described below is actually a problem for Rmpi and any other
  parallel implementation we tested leading to endless 
 executions in some
  cases, where the total data passed is huge.
 
  Assume the below 'mycall' is the function that takes data 
 and a function
  object, serializes them and calls the remote host. To make 
 it runable I
  just print the size of the serialized objects. In a parallel apply
  implemention it would serialize individual list elements 
 and a function
  and pass those over. Assuming 1 element is 1Mb and having 
 100 elements
  and a function as simple as function(z) z we would expect 
 to pass around
  100Mb of data, 1 Mb to each individual process. However 
 what happens is
  that in some situations all 100Mb of data are passed to all 
 the slaves
  as the function is serialized to include all of the data! 
 This always
  happens when we make such a call from an S4 method when the 
 function we
  is defined inline, see last example. 
 
  Anybody can explain this, and possibly suggest a solution? 
 Well, one is
  -- do not define functions to call in the same environment 
 as the caller
  :(
 
  I do not have immediate access to the newest version of R, 
 so would be
  grateful if sombody could test it in that and let me know 
 if the problem
  is still there. The example is runnable.
 
  Thanks,
  Oleg
 
  Dr Oleg Sklyar
  Research Technologist
  AHL / Man Investments Ltd
  +44 (0)20 7144 3803
  oskl...@maninvestments.com
 
  
 --
 --
  ---
 
  mycall = function(x, fun) {
  FUN = serialize(fun, NULL)
  DAT = serialize(x, NULL)
  
  cat(sprintf(length FUN=%d; length DAT=%d\n, length(FUN),
  length(DAT)))
  invisible(NULL) ## return results of a call on a remote 
 host with
  FUN and DAN
  }
 
  ## the function variant I  will be passing into mycall
  innerfun = function(z) z
  x = runif(1e6)
 
  ## test run from the command line
  mycall(x, innerfun)
  # output: length FUN=106; length DAT=822
 
  ## test run from within a function
  outerfun1 = function(x) mycall(x, innerfun)
  outerfun1(x)
  # output: length FUN=106; length DAT=822
 
  ## test run from

Re: [Rd] Changing the compiler gfortran to ifort

2009-08-11 Thread Sklyar, Oleg (London)
on Unix alikes possibly:

env F77=/path/to/ifort ./configure --prefix=/where/to/install

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
oskl...@maninvestments.com 

 -Original Message-
 From: r-devel-boun...@r-project.org 
 [mailto:r-devel-boun...@r-project.org] On Behalf Of Fabio 
 Mathias Corrêa
 Sent: 07 August 2009 14:44
 To: r-devel@r-project.org
 Subject: [Rd] Changing the compiler gfortran to ifort
 
 I tried the manual R Installation and Administration to 
 change the gcc compiler to icc and ifort for gfotran. However 
 I could not find the correct path for the R to identify the 
 icc and ifort.
 In which file I define the change of compiler?
 
 Thanks very much!!!
 
  Fábio Mathias Corrêa
 Estatística e Experimentação Agropecuária/UFLA
 Brazil
 
 
   
 __
 __
 Veja quais são os assuntos do momento no Yahoo! +Buscados
 http://br.maisbuscados.yahoo.com
 
 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel
 

**
 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] CTRL-C during .Call causes R to quit to command line

2009-03-30 Thread Sklyar, Oleg (London)
If you use JNI or rJava, you should start the VM with -Xrs argument,
otherwise the descibed things happen as Java catches the Ctrl-C
interrupt

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
oskl...@maninvestments.com 

 -Original Message-
 From: r-devel-boun...@r-project.org 
 [mailto:r-devel-boun...@r-project.org] On Behalf Of Saptarshi Guha
 Sent: 30 March 2009 04:24
 To: r-devel@r-project.org
 Subject: [Rd] CTRL-C during .Call causes R to quit to command line
 
 Hello,
 During a .Call e.g
 while(TRUE){
 value -rhsqnextKVR(rdr)  ## has .Call in this function
 if(is.null(value)) break;
   }
 if I press CTRL-C, R exits straight to the command line.
 
 Q: How can I prevent this? I should point out that my library uses
 JNI, so I'm not sure if that is causing it.
 I'm using R-2.8 on Linux (RHEL 5)
 Thank you in advance
 Regards
 Saptarshi
 
 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel
 

**
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


[Rd] imporving performance of slicing on matrices and S4 their derivatives

2009-03-27 Thread Sklyar, Oleg (London)
Dear list.

It is a known issue that accessing slots of S4 objects and in particular
accessing .Data slots is slow in R. However, what surprises me are two
things demonstrated in the code below (runnable with 'inline', my times
are in the comments):

- copying data out of a large 3x1e7 .Data slot into a matrix can be
easily made 3-4 times faster than accessing a .Data slot which I believe
grabs a reference (and as copying can be avoided the acceleration should
be even more dramatic). It is surprising that this memory inefficient
operation is faster than such a simple thing like getting a reference!

- getting a column, or columns, from an atomic R matrix or actually an
S4 object derived from it, can be up to 10 times faster than using
standard slicing with the [-operator (yes, less generic, but with such
performance gain we do definitely use it).

My point is: should not [-operators for atomic objects and @.Data be
redesigned? The code here is just an example for double storage-mode and
without any checks though. Adding checks and colnames etc does not lead
to performance degradation.

I was originally thinking that the dispatch looking up a particular [
implementation for an object is the issue, but in fact it is not the
case as redefining [ or $ as S4 methods (!) to use the mcol below for an
S4 object shows the same performance gains as the diret use of use of
mcol/mcols!

Any comments welcome!


## --- code 
## available from CRAN, needs compilers installed
library(inline)

## get 1 column of a matrix to use instead of [-operator 
## (same performance gains if index is a character or on multiple
columns or
## when getting multiple columns as matrix and assigning the names from
input)

body = /* test for column extraction: no checks here for code
simplicity */
int nrow = Rf_nrows(m);
int i = INTEGER(index)[0] - 1;
SEXP res;
PROTECT(res = allocVector(REALSXP, nrow));
memcpy(REAL(res), (REAL(m)[i*nrow]), nrow*sizeof(double));
UNPROTECT(1);
return res;

mcol = cfunction(signature(m=matrix, index=integer), body=body, 
includes=#include string.h)

## get A COPY of the @.Data slot from an object derived from
numeric/matrix

body = /* test performance of getting A COPY of @.Data, keeping
dimnames */
int nrow = Rf_nrows(m);
int ncol = Rf_ncols(m);
SEXP res, dim;
PROTECT(res = allocVector(REALSXP, nrow*ncol));
PROTECT(dim = allocVector(INTSXP, 2));
INTEGER(dim)[0] = nrow;
INTEGER(dim)[1] = ncol;
SET_DIM(res, dim);
if (GET_DIMNAMES(m)!= R_NilValue)
SET_DIMNAMES(res, Rf_duplicate(GET_DIMNAMES(m)));
if (ncol0  nrow0)
memcpy(REAL(res), REAL(m), nrow*ncol*sizeof(double));
UNPROTECT(2);
return res;

mcols = cfunction(signature(m=matrix), body=body, 
includes=#include string.h)

## --- tests ---
m = matrix(runif(3e7), nc=3)

setClass(MyClass, representation(matrix, comment=character))
dat = new(MyClass, m, comment=test object)

mean(sapply(1:20, function(i) system.time(d...@.data)[1] ))
## output: [1] 0.2526
mean(sapply(1:20, function(i) system.time(mcols(dat))[1] ))
## output: [1] 0.08215

mean(sapply(1:50, function(i) system.time(m[,2])[1] ))
## output: [1] 0.1222
mean(sapply(1:50, function(i) system.time(mcol(m,2L))[1] ))
## output: [1] 0.02596
mean(sapply(1:50, function(i) system.time(dat[,2])[1] ))
## output: [1] 0.1269
mean(sapply(1:50, function(i) system.time(mcol(dat,2L))[1] ))
## output: [1] 0.02584

---
 sessionInfo()
R version 2.9.0 Under development (unstable) (2009-02-02 r47821) 
x86_64-unknown-linux-gnu 

locale:
C

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


other attached packages:
[1] inline_0.3.3



Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
oskl...@maninvestments.com

**
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


[Rd] consistent segfaults in ROracle with one of the databases

2009-03-27 Thread Sklyar, Oleg (London)
Dear list.

Has anybody had any issues with ROracle, namely consistently leading to
a segmentation fault? One of our oracle databases seems to have certain
issues at the moment (do not know what exactly though) and if that one
is queried ROracle definitely fails with a segmentation fault. Any
ideas? Here is the trace and below is also a type of query that crashes
it:

 *** caught segfault ***
address 0x1, cause 'memory not mapped'

Traceback:
 1: .Call(RS_Ora_exec, ps = as(ps, integer), data = data,
data.classes = df.classes, buf.size = as.integer(ora.buf.size),
PACKAGE = .OraPkgName)
 2: oraExecStatement(ps, ora.buf.size = as(ora.buf.size, integer))
 3: doTryCatch(return(expr), name, parentenv, handler)
 4: tryCatchOne(expr, names, parentenv, handlers[[1L]])
 5: tryCatchList(expr, classes, parentenv, handlers)
 6: tryCatch(expr, error = function(e) {call - conditionCall(e)
if (!is.null(call)) {if (identical(call[[1L]],
quote(doTryCatch))) call - sys.call(-4L)dcall -
deparse(call)[1L]prefix - paste(Error in, dcall, : )
LONG - 75Lmsg - conditionMessage(e)sm - strsplit(msg,
\n)[[1L]]if (14L + nchar(dcall, type = w) + nchar(sm[1L],
type = w)  LONG) prefix - paste(prefix, \n
, sep = )}else prefix - Error : msg - paste(prefix,
conditionMessage(e), \n, sep = )
.Internal(seterrmessage(msg[1L]))if (!silent 
identical(getOption(show.error.messages), TRUE)) {
cat(msg, file = stderr()).Internal(printDeferredWarnings())}
invisible(structure(msg, class = try-error))})
 7: try({ps - oraPrepareStatement(con, statement, bind = NULL)
rs - oraExecStatement(ps, ora.buf.size = as(ora.buf.size,
integer))})
 8: oraExecDirect(con, statement, ...)
 9: oraQuickSQL(conn, statement, ...)
10: dbGetQuery(dotsConnection(), qry)

--
This is the type of query (template) that crashes it, I know this is not
too helpful as you cannot run it, but maybe someone spots a certain
pattern in it:

SELECT TIMESTAMP, VALUE, VM FROM
(WITH ev AS
(SELECT audit_key_new key, audit_date dt, audit_batch_nbr,
audit_date
FROM dots_audit.audit_event
WHERE table_name='VALUE_PROPERTY_MAP'),
jfsm AS
(SELECT audit_key, fund_id, fund_mult
FROM dots_audit.value_property_map WHERE property_id='%s'
 UNION SELECT audit_key, value_id, value_mult
FROM dots.value_property_map WHERE property_id='%s')
SELECT DISTINCT
ev.dt - to_date('01011970','ddmm') TIMESTAMP,
jfsm.value_id VALUE,
jfsm.value_mult VM,
RANK() OVER (PARTITION BY audit_batch_nbr, value_id ORDER BY dt
DESC) r
FROM jfsm, ev WHERE audit_key=ev.key)
WHERE r=1 ORDER BY TIMESTAMP DESC 

--
 library(ROracle)
Loading required package: DBI
 sessionInfo()
R version 2.9.0 Under development (unstable) (2009-02-02 r47821) 
x86_64-unknown-linux-gnu 

locale:
LC_CTYPE=en_GB;LC_NUMERIC=C;LC_TIME=en_GB;LC_COLLATE=C;LC_MONETARY=C;LC_
MESSAGES=en_GB;LC_PAPER=en_GB;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_M
EASUREMENT=en_GB;LC_IDENTIFICATION=C

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


other attached packages:
[1] ROracle_0.5-9 DBI_0.2-4

--

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
oskl...@maninvestments.com

**
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


[Rd] typo in sprintf format string segfaults R

2009-03-26 Thread Sklyar, Oleg (London)
typo as simple as %S instead of %s segfaults R devel:

*** R 2.9.0 (svn -r 47821) [/share/research/R-devel/20090203/lib64/R]
***
 sprintf(%S%d, aaa, 1)

 *** caught segfault ***
address 0x8000, cause 'memory not mapped'

Traceback:
 1: sprintf(%S%d, aaa, 1)

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace

-
 sessionInfo()
R version 2.9.0 Under development (unstable) (2009-02-02 r47821) 
x86_64-unknown-linux-gnu 

locale:
C

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


Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
oskl...@maninvestments.com

**
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


[Rd] Rd \usage clause for an S4 replace method

2009-03-13 Thread Sklyar, Oleg (London)
Given S4 methods [ and [-, how do I write the Rd-file usage clause for
the latter one?
What I have now is:

\S4method{[}{TimeSeries,TimeDate,missing}(x, i, j, ..., drop)
\S4method{[-}{TimeSeries,TimeDate,missing,ANY}(x, i, j, ..., value)

which results in the following output:

## S4 method for signature 'TimeSeries, TimeDate, missing':
x[i, j, ..., drop]
\S4method{[-}{TimeSeries,TimeDate,missing,ANY}(x, i, j, ..., value)

How should I document the latter? Thanks.


Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
oskl...@maninvestments.com

**
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] S4 generic masking S3 generic when using namespace

2009-03-10 Thread Sklyar, Oleg (London)
Try using setGeneric(predict) without further arguments, this should
work as it will take the existing 'predict' definition and convert it
into S4 generic. This works nicely for me for all plot, print etc
methods

* R   
*** R 2.9.0 (svn -r 47821) [/share/research/R-devel/20090203/lib64/R]
***
 setGeneric(predict)
[1] predict
 predict
standardGeneric for predict defined from package stats

function (object, ...) 
standardGeneric(predict)
environment: 0xe24b080
Methods may be defined for arguments: object
Use  showMethods(predict)  for currently available ones.

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
oskl...@maninvestments.com 

 -Original Message-
 From: r-devel-boun...@r-project.org 
 [mailto:r-devel-boun...@r-project.org] On Behalf Of Gad Abraham
 Sent: 10 March 2009 10:02
 To: R-devel@r-project.org
 Subject: [Rd] S4 generic masking S3 generic when using namespace
 
 Hi,
 
 I have two example packages, test1 and test2, where the only code in 
 them is:
 
 setGeneric(predict, function(object, ...) 
 standardGeneric(predict))
 
 (get them from http://www.cs.mu.oz.au/~gabraham/test1.tar and 
 http://www.cs.mu.oz.au/~gabraham/test2.tar)
 
 The difference between them is that first does not have a 
 namespace, and 
 loads fine. The second has a namespace but generates a warning:
   library(test2)
 
 Attaching package: 'test2'
 
 
   The following object(s) are masked from package:stats :
 
predict
 
 
 
 Is this an intended behaviour? If I ignore this masking warning, do I 
 risk unintended consequences later down the track?
 
 Thanks,
 Gad
 
 
 
   sessionInfo()
 R version 2.8.1 (2008-12-22)
 i386-apple-darwin8.11.1
 
 locale:
 en_AU.UTF-8/en_AU.UTF-8/C/C/en_AU.UTF-8/en_AU.UTF-8
 
 attached base packages:
 [1] stats graphics  grDevices utils datasets  methods   base
 
 other attached packages:
 [1] test2_0.1
 
 
 -- 
 Gad Abraham
 MEng Student, Dept. CSSE and NICTA
 The University of Melbourne
 Parkville 3010, Victoria, Australia
 email: gabra...@csse.unimelb.edu.au
 web: http://www.csse.unimelb.edu.au/~gabraham
 
 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel
 

**
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


[Rd] interactive graphics for R: was Google Summer of Code 2009

2009-02-19 Thread Sklyar, Oleg (London)
Dear Simon, 

thanks for comments.

I better give a bit of a background first. We are analysing time series of 
financial data, often multivariate and with say 200K samples. It is quite a 
frequent situation that one needs to display multivariate time series of say 
200K rows and 10 columns over the whole time range and be able to zoom in to 
look for effects of interest. The obvious choice of plots is a multiplot window 
with a shared x-axis, in this case time, zooming should be done simultaneously 
in all time series displayed.

I do understand this is a very specific example, but I am sure similar problems 
arise in other discilines: think of a genomic browser, sequencing or any other 
non-financial time series data etc. 

Essentially, no matter what the graphying or rendering technology used beneath 
(GTK, QT or anything else), my requirements, and yes they are in a way 
subjective, but on the other hand quite generic, would be a possibliity to 
produce multiplot windows (similar to say setting mfrow in par) with two simple 
features: zooming and panning simultaneously on all plots or independently. The 
support for Axis/pretty method callbacks is required because those are the 
methods that provide correct axis labeling independently on the class of the 
data. This is essentially the only thing that is not supported by the 
gtkdatabox widget as the rulers can only display numbers.

On the other issues of interactivity, I agree it is quite a broad term, but the 
functionality I describe above is pretty much basic.

As for Java objections: this is not because Java is slow on its own, but the 
interface is not native, requires a huge JVM for a fairly simple task and the 
interface is relatively slow and cumbersome. As soon as I see a package 
demonstrating good performance via rJava, I will be happy to say I was wrong. 
But essentially the same problem with 'playwith' package mentioned earlier -- 
it uses RGtk, gWidgets and therefore it is slow -- it is not that GTK is slow, 
but the complex binding from R via RGtk to GTK. If used natively, it is very 
fast.

 As for iPlots, the development has shifted a while ago from 
 the 'old'  
 iPlots to the new ones which are in development stage (as I 
 said they  
 are announced for the useR! conference). My point was not about  
 telling you to use a specific software, it was rather about 
 making you  
 aware of the fact that what you describe already exists (ggobi  
 definitely is IG in GTK) and/or is worked on (iPlots 3.0) with  
 possibly better approach.

Where can I find it to have a look? No matter that it is in development, if it 
fits the needs, I will only be happy to contribute what I can.

 
  3) I have a prototype using gtkdatabox for very fast interactive  
  plots in R using GTK, but it is limited by the capabilities of the  
  gtkdatabox widget, not that of R or GTK as such.
 
 
 I don't know about your prototype, so I cannot really comment 
 on that,  
 but gtkdatabox is not IG, either.
 

I cannot send you an example of an R package using gtkdatabox from the office, 
but I will create a small demo pack at home and will send it to you separately 
as to indicate what I am looking into. Possibly it is not IG, but this is 
essentially what I described above, although quite primitive (but it was a 
one-day project for me, not 3-months).

 
  I do think there is a need for an interactive graphics 
 package for R.
 
 
 I do completely agree with that, but interactive means it satisfies  
 basic requirements on IG such as the availability of selection,  
 highlighting, queries, interactive change of parameters etc. This is  
 not about 2d/3d clouds at all - that we have for decades 
 already. Also  
 this is not about hacks to glue on interactivity to existing  
 graphics systems with a chewing gum. We need a versatile (possible  
 extensible) set of interactive statistical plots -- at least that's  
 what our experience shows.

Agree completely.

 
 Cheers,
 Simon
 
 
 
  -Original Message-
  From: Simon Urbanek [mailto:simon.urba...@r-project.org]
  Sent: 19 February 2009 14:34
  To: Sklyar, Oleg (London)
  Cc: Friedrich Leisch; r-devel@r-project.org;
  manuel.eugs...@stat.uni-muenchen.de
  Subject: Re: [Rd] Google Summer of Code 2009
 
 
  On Feb 19, 2009, at 6:38 , Sklyar, Oleg (London) wrote:
 
  Two ideas:
 
  1) A library for interactive plots in R
 
  R lacks functionality that would allow displaying of interactive
  plots with two distinct functionalities: zooming and panning. This
  functionality is extremely important for the analysis of
  large, high
  frequency, data sets spanning over large ranges (in time as well).
  The functionality should acknowledge Axis methods in callbacks on
  rescale (so that it could be extended to user-specific classes for
  axis generation) and should have a native C interface to R
  (i.e. no
  Java, but such cross platform widgets like GTK or QT or anything
  similar that does not require heavy

Re: [Rd] Google Summer of Code 2009

2009-02-19 Thread Sklyar, Oleg (London)
Two ideas:

1) A library for interactive plots in R

R lacks functionality that would allow displaying of interactive plots with two 
distinct functionalities: zooming and panning. This functionality is extremely 
important for the analysis of large, high frequency, data sets spanning over 
large ranges (in time as well). The functionality should acknowledge Axis 
methods in callbacks on rescale (so that it could be extended to user-specific 
classes for axis generation) and should have a native C interface to R (i.e. no 
Java, but such cross platform widgets like GTK or QT or anything similar that 
does not require heavy-weight add-ons). GTK has been used successfully from 
within R in many applications (RGtk, rgobby, EBImage etc) on both *nix and 
Windows, and thus could be a preferential option, it is also extremely easy to 
integrate into R. The existing tools (e.g. iplots) are slow, unstable and lack 
support for time/date plots (or actually any non-standard axes) and they are 
all Java. We are looking into stanard xy-plots as well as image and 3D plots. 
Obviously one can think of further interactivity, but this would be too much 
for the Summer of Code project. A good prototype would already be a step 
forward.

2) Cross platform GUI debugger, preferably further Eclipse integration (beyond 
StatET capabilities)

Tibco has recently released the S+ workbench for eclipse which has a reasonable 
support for non-command line debugging. In the R community, the StatET eclipse 
plugin mimics a lot of code development functionality of S+ workbench, but has 
poor support for in-line execution of R sessions in eclipse and does not have 
debugging capabilities. Supporting this project further, or developing a GUI 
debugger independent of eclipse, are both acceptable options. The debugger 
should allow breakpoints, variable views etc.

For both of the above, our interest is mostly on the Linux side, but one should 
look into cross-platform solutions.

Regards,
Oleg

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
oskl...@maninvestments.com 

 -Original Message-
 From: r-devel-boun...@r-project.org 
 [mailto:r-devel-boun...@r-project.org] On Behalf Of Friedrich Leisch
 Sent: 18 February 2009 22:54
 To: r-devel@r-project.org
 Cc: manuel.eugs...@stat.uni-muenchen.de
 Subject: [Rd] Google Summer of Code 2009
 
 
 Hi,
 
 in approximately one months time mentoring institutions can propose
 projects for the Google Summer of Code 2009, see
 
   http://code.google.com/soc/
 
 Last year the R Foundation succesfully participated with 4 projects,
 see http://www.r-project.org/SoC08/ for details.  We want to
 participate again this year. Our project proposals will be managed by
 Manuel Eugster (email address in CC). Manuel is one of my PhD students
 and mentored the Roxygen project last year. This mail is mainly
 intended to make you aware of the program, Manuel will send a followup
 email with more technical details in the next days.
 
 In this phase we are looking for potential mentors who can offer
 interesting projects to students.  I don't think that we will get much
 more than 4-6 projects, so don't be disappointed if you propose
 something and don't get selected.
 
 There are two selection steps involved: (a) The R Foundation has to
 compile an official ideas list of projects, for which students can
 apply. Last year we had 8 of those. After that, we (b) get a certain
 number of slots from Google (4 last year) and all prospective project
 mentors can vote on which projects actually get funding.
 
 Currently we are looking for good ideas for phase (a). I give no
 guarantees that all ideas will get on our official ideas list, what we
 pick depends on the number of submissions and topics, respectively. We
 want to make sure to have a broad range of themes, it is unlikely,
 that we will, e.g., pick 10 database projects. Also keep in mind that
 students have only three months time. This is not a research exercise
 for the students, you should have a rough idea what needs to be done.
 
 Last year we had a majority of infrastructure projects, and only few
 with focus on statistical algorithms. We got a lot of applications for
 the latter, so don't hesitate to formulate projects in that
 direction. Important infrastructure may get precedence over
 specialized algorithms, though, because the whole community can benfit
 from those. But that will be a decision in phase (b), and we are not
 there yet.
 
 Please don't send any ideas to me right now, wait for the above
 mentioned email by Manuel on the technical details for idea 
 submission.
 
 Best,
 Fritz
 
 -- 
 --
 -
 Prof. Dr. Friedrich Leisch 
 
 Institut für Statistik  Tel: (+49 89) 
 2180 3165
 Ludwig-Maximilians-Universität  Fax: (+49 89) 
 2180 5308
 Ludwigstraße 33
 D-80539 München 
 

Re: [Rd] Google Summer of Code 2009

2009-02-19 Thread Sklyar, Oleg (London)
Simon,

I would not like to take it offline as I disagree with your points and think it 
is fair to let other users know why. To make it clear first, I am most 
interested in 2D, not 3D plots, and rgobbi is not a good enough solution, 
unfortunately.

1) I spent loads of time looking for good, if any at all, interactive graphics 
packages for R. There are hardly many, and apart from rgl there are no good 
ones as I see it. I do accept that this can be subjective, but I think many 
people will share my opinion.

2) With respect to iplots:

http://cran.r-project.org/web/packages/iplots/index.html states:
Version:1.1-3
Depends:R (≥ 1.5.0), methods, rJava (≥ 0.5-0)

http://www.rosuda.org/iplots/ states:
News:

* 2007/08/07 Released iplots_1.1-1 on CRAN...

There might be version 3 available somewhere, but it is not obvious where and 
the above one is Java based. I have tried the above version about 4 months ago 
-- it was slow, unstable and did not have any support for time axis at all. If 
I find it, I will give it a try and will be able to post corresponding comments.

2) rggobi is not a solution for 2D graphics at all and this is what is missing 
in R. I would not mention rgobbi myself having had no look at it first. 
However, if somebody works on interactive 2D plots, there is no reason why this 
person should think of 3D as well to have all in one framework.

3) I have a prototype using gtkdatabox for very fast interactive plots in R 
using GTK, but it is limited by the capabilities of the gtkdatabox widget, not 
that of R or GTK as such.

I do think there is a need for an interactive graphics package for R.

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
oskl...@maninvestments.com 

 -Original Message-
 From: Simon Urbanek [mailto:simon.urba...@r-project.org] 
 Sent: 19 February 2009 14:34
 To: Sklyar, Oleg (London)
 Cc: Friedrich Leisch; r-devel@r-project.org; 
 manuel.eugs...@stat.uni-muenchen.de
 Subject: Re: [Rd] Google Summer of Code 2009
 
 
 On Feb 19, 2009, at 6:38 , Sklyar, Oleg (London) wrote:
 
  Two ideas:
 
  1) A library for interactive plots in R
 
  R lacks functionality that would allow displaying of interactive  
  plots with two distinct functionalities: zooming and panning. This  
  functionality is extremely important for the analysis of 
 large, high  
  frequency, data sets spanning over large ranges (in time as well).  
  The functionality should acknowledge Axis methods in callbacks on  
  rescale (so that it could be extended to user-specific classes for  
  axis generation) and should have a native C interface to R 
 (i.e. no  
  Java, but such cross platform widgets like GTK or QT or anything  
  similar that does not require heavy-weight add-ons). GTK has been  
  used successfully from within R in many applications (RGtk, 
 rgobby,  
  EBImage etc) on both *nix and Windows, and thus could be a  
  preferential option, it is also extremely easy to integrate 
 into R.  
  The existing tools (e.g. iplots) are slow, unstable and 
 lack support  
  for time/date plots (or actually any non-standard axes) and 
 they are  
  all Java. We are looking into stanard xy-plots as well as 
 image and  
  3D plots. Obviously one can think of further interactivity, 
 but this  
  would be too much for the Summer of Code project. A good prototype  
  would already be a step forward.
 
 
 If primitive 3d scatterplot interactivity is all you want, go with  
 rggobi. It's GTK and has all this already and much more. However,  
 ggobi also shows why GTK is not a good choice for general 
 interactive  
 graphics toolkit - it [GTK] is slow and lacks reasonable graphics  
 support. OpenGL is IMHO a better way to go since IG don't really  
 leverage any of the widgets (you get them for free via R widgets  
 packages anyway) and OpenGL gives you excellent speed, alpha-support  
 and anti-aliasing etc.
 
 As you can imagine I don't agree with most of your statements above  
 and I'm happy to discuss them in a separate thread. Just as an aside  
 iPlots 3.0 (announced for useR!/DSC) are no longer Java based 
 and have  
 a native C interface.
 
 Cheers,
 S
 
 
  2) Cross platform GUI debugger, preferably further Eclipse  
  integration (beyond StatET capabilities)
 
  Tibco has recently released the S+ workbench for eclipse 
 which has a  
  reasonable support for non-command line debugging. In the R  
  community, the StatET eclipse plugin mimics a lot of code  
  development functionality of S+ workbench, but has poor 
 support for  
  in-line execution of R sessions in eclipse and does not have  
  debugging capabilities. Supporting this project further, or  
  developing a GUI debugger independent of eclipse, are both  
  acceptable options. The debugger should allow breakpoints, 
 variable  
  views etc.
 
  For both of the above, our interest is mostly on the Linux 
 side, but  
  one should look into cross-platform solutions

Re: [Rd] Google Summer of Code 2009

2009-02-19 Thread Sklyar, Oleg (London)
Thanks for pointing out. playwith looks quite interesting

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
oskl...@maninvestments.com 

 -Original Message-
 From: Liviu Andronic [mailto:landronim...@gmail.com] 
 Sent: 19 February 2009 15:11
 To: Sklyar, Oleg (London)
 Cc: Simon Urbanek; Friedrich Leisch; 
 manuel.eugs...@stat.uni-muenchen.de; r-devel@r-project.org
 Subject: Re: [Rd] Google Summer of Code 2009
 
 On Thu, Feb 19, 2009 at 3:47 PM, Sklyar, Oleg (London)
 oskl...@maninvestments.com wrote:
  I do think there is a need for an interactive graphics 
 package for R.
 
 There are also the GTK-based playwith, and latticist; unsure though
 whether they fit your requirements.
 Liviu
 
 
 
 -- 
 Do you know how to read?
 http://www.alienetworks.com/srtest.cfm
 Do you know how to write?
 http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail
 

**
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] Google Summer of Code 2009

2009-02-19 Thread Sklyar, Oleg (London)
Dear Yihui,

I am sure there are many possibilities available, but I am not looking for a 
hack and rather for a versatile high-quality solution. It solution should be 
fast, reliable and developed to a high standard. Moreover, on my X11 RHEL5 
x86_64 I get the following:

 getGraphicsEvent(onKeybd = keybd)
Error in getGraphicsEvent(onKeybd = keybd) : 
  graphics device does not support graphics events

Furthermore, one could think of a library displaying multiple plots, for 
multivariate data, allowing simultaneous zoom into all of the plots.

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
oskl...@maninvestments.com 

 -Original Message-
 From: Yihui Xie [mailto:xieyi...@gmail.com] 
 Sent: 19 February 2009 16:20
 To: Sklyar, Oleg (London)
 Cc: Liviu Andronic; Friedrich Leisch; Simon Urbanek; 
 manuel.eugs...@stat.uni-muenchen.de; r-devel@r-project.org
 Subject: Re: [Rd] Google Summer of Code 2009
 
 Well, for the first idea, isn't it easy enough to fulfill zooming or
 panning using getGraphicsEvent() in the grDevices package? For example
 (using keys +/-/Left/Right/Up/Down/* to zoom and pan):
 
 ##
 # a demo for zooming and panning in R graphics
 # by Yihui Xie xieyi...@gmail.com Feb 20, 2009
 ##
 # a large number of points
 plot(x - rnorm(5000), y - rnorm(5000), xlab = x, ylab = y)
 xylim - c(range(x), range(y))
 zoom - function(d, speed = 0.05) {
 rx - speed * (xylim[2] - xylim[1])
 ry - speed * (xylim[4] - xylim[3])
 # global assignment '-' here!
 xylim - xylim + d * c(rx, -rx, ry, -ry)
 plot(x, y, xlim = xylim[1:2], ylim = xylim[3:4])
 NULL
 }
 # Key `+`: zoom in; `-`: zoom out
 # Left, Right, Up, Down: self-explaining
 # `*`: reset
 # Press other keys to quit
 keybd - function(key) {
 switch(key, `+` = zoom(1), `-` = zoom(-1), Left = zoom(c(-1,
 1, 0, 0)), Right = zoom(c(1, -1, 0, 0)), Up = zoom(c(0,
 0, 1, -1)), Down = zoom(c(0, 0, -1, 1)), `*` = plot(x,
 y), Quit the program)
 }
 getGraphicsEvent(onKeybd = keybd)
 ##
 
 Regards,
 Yihui
 --
 Yihui Xie xieyi...@gmail.com
 Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086
 Mobile: +86-15810805877
 Homepage: http://www.yihui.name
 School of Statistics, Room 1037, Mingde Main Building,
 Renmin University of China, Beijing, 100872, China
 
 
 
 On Thu, Feb 19, 2009 at 7:38 PM, Sklyar, Oleg (London)
 oskl...@maninvestments.com wrote:
  Two ideas:
 
  1) A library for interactive plots in R
 
  R lacks functionality that would allow displaying of 
 interactive plots with two distinct functionalities: zooming 
 and panning. This functionality is extremely important for 
 the analysis of large, high frequency, data sets spanning 
 over large ranges (in time as well). The functionality should 
 acknowledge Axis methods in callbacks on rescale (so that it 
 could be extended to user-specific classes for axis 
 generation) and should have a native C interface to R (i.e. 
 no Java, but such cross platform widgets like GTK or QT or 
 anything similar that does not require heavy-weight add-ons). 
 GTK has been used successfully from within R in many 
 applications (RGtk, rgobby, EBImage etc) on both *nix and 
 Windows, and thus could be a preferential option, it is also 
 extremely easy to integrate into R. The existing tools (e.g. 
 iplots) are slow, unstable and lack support for time/date 
 plots (or actually any non-standard axes) and they are all 
 Java. We are looking into stanard xy-plots as well as image 
 and 3D plots. Obviously one can think of further 
 interactivity, but this would be too much for the Summer of 
 Code project. A good prototype would already be a step forward.
 
  2) Cross platform GUI debugger, preferably further Eclipse 
 integration (beyond StatET capabilities)
 
  Tibco has recently released the S+ workbench for eclipse 
 which has a reasonable support for non-command line 
 debugging. In the R community, the StatET eclipse plugin 
 mimics a lot of code development functionality of S+ 
 workbench, but has poor support for in-line execution of R 
 sessions in eclipse and does not have debugging capabilities. 
 Supporting this project further, or developing a GUI debugger 
 independent of eclipse, are both acceptable options. The 
 debugger should allow breakpoints, variable views etc.
 
  For both of the above, our interest is mostly on the Linux 
 side, but one should look into cross-platform solutions.
 
  Regards,
  Oleg
 
  Dr Oleg Sklyar
  Research Technologist
  AHL / Man Investments Ltd
  +44 (0)20 7144 3107
  oskl...@maninvestments.com
 
  -Original Message-
  From: r-devel-boun...@r-project.org
  [mailto:r-devel-boun...@r-project.org] On Behalf Of 
 Friedrich Leisch
  Sent: 18 February 2009 22:54
  To: r-devel@r-project.org
  Cc

Re: [Rd] setClassUnion with numeric; extending class union

2009-02-12 Thread Sklyar, Oleg (London)
Hi John,

sorry for not posting more info. Strangely I get warnings about
setClassUnion with numeric in a very special case: if I define it in a
clean R session then there are no warnings, however if I load a number
of my packages where there are other classes derived from numeric and
exported then I get the following warnings:

 setClassUnion(numericOrNULL, c(numeric,NULL))
[1] numericOrNULL
Warning messages:
1: In .checkSubclasses(class1, classDef, class2, classDef2, where1,  :
  Subclass TimeDateBase of class numeric is not local and cannot be
updated for new inheritance information; consider setClassUnion()
2: In .checkSubclasses(class1, classDef, class2, classDef2, where1,  :
  Subclass TimeDate of class numeric is not local and cannot be
updated for new inheritance information; consider setClassUnion()
3: In .checkSubclasses(class1, classDef, class2, classDef2, where1,  :
  Subclass Time of class numeric is not local and cannot be updated
for new inheritance information; consider setClassUnion()

The class is operational even with those warnings though. Now, the above
classes are defined as follows:

## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - 
setClass(TimeDateBase, 
representation(numeric, mode=character),
prototype(mode=posix)
)

## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - 
setClass(TimeDate,
representation(TimeDateBase, tzone=character),
prototype(tzone=Europe/London)
)

## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - 
setClass(Time, 
representation(TimeDateBase)
)

Theses classes work perfectly fine on their own and are used throughout
our code for all possible time and date operations extending the
existing functionality of R and available third party packages by an
order of magnitude. I do not see a relation between the above class
definitions and the newly defined class union though apart from the fact
that they are in a package namespace and therefore locked. Sorry I
cannot provide more source code as the code is not yet public.

It would definitely be nice to somehow have a .Data slot in NULL or even
a data.frame, although I do understand that this is quite a substantial
piece of work to make it all robust and backward compatible.

 sessionInfo() ## of a clean session

R version 2.9.0 Under development (unstable) (2009-02-02 r47821) 
x86_64-unknown-linux-gnu 

locale:
C

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


Any thoughts are greatly appreciated.

Kind regards,
Oleg

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
oskl...@maninvestments.com 

 -Original Message-
 From: John Chambers [mailto:j...@r-project.org] 
 Sent: 11 February 2009 20:40
 To: Sklyar, Oleg (London)
 Cc: r-devel@r-project.org
 Subject: Re: [Rd] setClassUnion with numeric; extending class union
 
 So, I was intrigued and played around a bit more.  Still 
 can't get any 
 warnings, but the following may be the issue.
 
 One thing NOT currently possible is to have a class that has 
 NULL as its 
 data part, because type NULL is abnormal and can't have attributes.
 
 So if you want a class that contains a union including NULL, 
 you're in 
 trouble generating a value from the class that is NULL.  It's 
 not really 
 a consequence of the setUnion() per se.
 
   setClass(bar, contains = numericOrNULL)
 [1] bar
   zz = new(bar, NULL)
 Error in validObject(.Object) :
   invalid class bar object: invalid object for slot .Data 
 in class 
 bar: got class list, should be or extend class numericOrNULL
 
 (How one got from the error to the message is a question, but in any 
 case this can't currently work.)
 
 As in my example and in your example with a slot called data, no 
 problem in having a slot value that is NULL.
 
 Looking ahead, I'm working on some extensions that would 
 allow classes 
 to contain abnormal data types (externalptr, environment, ...) by 
 using a reserved slot name, since one can not make the actual 
 data type 
 one of those types.
 
 John Chambers wrote:
  What warnings? Which part of the following is not what 
 you're looking 
  for? (The usual information is needed, like version of R, 
 reproducible 
  example, etc.)
 
 
   setClassUnion(numericOrNULL, c(numeric,NULL))
  [1] numericOrNULL
   setClass(foo, representation(x=numericOrNULL))
  [1] foo
   ff = new(foo, x= 1:10)
   fg = new(foo, x = NULL)
  
   ff
  An object of class foo
  Slot x:
  [1] 1 2 3 4 5 6 7 8 9 10
 
   fg
  An object of class foo
  Slot x:
  NULL
   fk = new(foo)
   fk
  An object of class foo
  Slot x:
  NULL
 
  John
 
  Sklyar, Oleg (London) wrote:
  Dear list:
 
  I am looking for a good way to create an S4 class that would extend
  numeric, but would allow NULL instead of data as well. As 
 far as I can
  see there is no way at the moment to do that, but please 
 correct me if I
  am wrong. The best solution

[Rd] setClassUnion with numeric; extending class union

2009-02-11 Thread Sklyar, Oleg (London)
Dear list:

I am looking for a good way to create an S4 class that would extend
numeric, but would allow NULL instead of data as well. As far as I can
see there is no way at the moment to do that, but please correct me if I
am wrong. The best solution I came up with so far was the following (it
also indicates a problem of using setClassUnion with numeric as one of
the classes):

I define a class union of numeric and NULL:

Unfortunately the following works only with warnings:
setClassUnion(numericOrNULL, c(numeric,NULL))

So I do a workaround as:

setClass(aNumeric, contains=numeric)
setClassUnion(numericOrNULL, c(aNumeric,NULL))

Then I cannot really extend the above virtual class and can only use it
in a user-defined slot as follows:

setClass(myClass, representation(data=numericOrNULL))
new(myClass, data=runif(20))
new(myClass, data=NULL)

and this works.

Obviously it would be nicer to have something like the following:

setClass(myClass, contains=numericOrNULL)
new(myClass, runif(20)) ## .Data is not a slot of myClass
setClass(myClass, representation(numericOrNULL))
new(myClass, runif(20)) ## ibid

Technically I understand that the reason behind it failing to work is
that the virtual class numericOrNULL has not got the .Data slot from
numeric, but it would be nice to have such a functionality.

Any ideas about better ways for solving such a problem than the one
described above?

Thanks.

Best,
Oleg

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
oskl...@maninvestments.com

**
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


[Rd] after some time R stopped returning from Rmpi calls

2009-01-29 Thread Sklyar, Oleg (London)
Hi,

this is not exactly a developer question, but maybe you have noticed
similar behaviour before. For quite some time R and Rmpi were working
perfectly for me until one day they just stopped doing so without any
changes in the configs. R still spawns jobs as requested, and if they
are small they run through and return, but as soon as their duration is
over 5s or so the spawned processes go to sleep and never return to the
head node. Below is the top of one of the slave nodes with the spawned
jobs, as you see their status is sleeping. It looks like a communication
problem between the master and the slave nodes, but this behaviour *is*
user specific: exactly the same script will work for some users and will
just lead to hanging for others.

Rmpi is installed with a default R CMD INSTALL without additional
arguments. LD_LIBRARY_PATH is set and the whole setup *was* working with
the same config. 

Has anybody experienced similar problems with Rmpi and LAM before?

Thank you,
Oleg

RHEL 5 x86_64, 16core Opteron

LAM 7.1.4/MPI 2 C++/ROMIO - Indiana University

It is quite a dated version of R I running now, but recent Rmpi.

 sessionInfo()
R version 2.9.0 Under development (unstable) (2008-09-30 r46585) 
x86_64-unknown-linux-gnu 

locale:
C

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


other attached packages:
[1] Rmpi_0.5-5

  PID USER  PR  NI  VIRT  RES  SHR S %CPU %MEMTIME+  COMMAND

 7699 osklyar   16   0 19128 1448 1000 S0  0.0   0:00.02 lamd

 7807 osklyar   16   0  8652  992  824 S0  0.0   0:00.01 Rslaves.sh

 7808 osklyar   16   0  8656  992  824 S0  0.0   0:00.01 Rslaves.sh

 7809 osklyar   16   0  8652  992  824 S0  0.0   0:00.00 Rslaves.sh

 7810 osklyar   17   0  8656  992  824 S0  0.0   0:00.01 Rslaves.sh

 7811 osklyar   18   0  8656  992  824 S0  0.0   0:00.02 Rslaves.sh

 7812 osklyar   18   0  8656  992  824 S0  0.0   0:00.02 Rslaves.sh

 7813 osklyar   18   0  8656  992  824 S0  0.0   0:00.02 Rslaves.sh

 7814 osklyar   18   0  8656  992  824 S0  0.0   0:00.02 Rslaves.sh

 7815 osklyar   15   0  165m  60m 4568 S0  0.2   0:03.66 R

 7816 osklyar   16   0  161m  56m 4568 S0  0.2   0:03.51 R

 7817 osklyar   15   0  161m  56m 4584 S0  0.2   0:03.82 R

 7818 osklyar   16   0  161m  56m 4568 S0  0.2   0:03.31 R

 7819 osklyar   16   0  165m  61m 4568 S0  0.2   0:03.59 R

 7820 osklyar   15   0  162m  58m 4568 S0  0.2   0:03.43 R

 7821 osklyar   16   0  162m  58m 4568 S0  0.2   0:03.26 R

 7824 osklyar   16   0  161m  56m 4568 S0  0.2   0:03.49 R

 7973 osklyar   15   0 87208 1880 1140 S0  0.0   0:00.00 sshd

 7974 osklyar   15   0 72332 1716 1276 S0  0.0   0:00.01 bash


Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
oskl...@maninvestments.com

**
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] Return values from .Call and garbage collection

2009-01-27 Thread Sklyar, Oleg (London)
- R is not multithreaded (or so it was) and thus race condition cannot
occur
- I would think there is no call to GC at the time of assignment of the
return value to a variable. GC is only called within other R calls as R
as mentioned above is not multithreaded

Most likely issue is your code itself, out of range indexing, failure to
initialise all elements of the allocated structure correctly, 1 and not
0-based indexing, use of other R variables for initialisation that
should have been protected but were not etc. 

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
oskl...@maninvestments.com 

 -Original Message-
 From: r-devel-boun...@r-project.org 
 [mailto:r-devel-boun...@r-project.org] On Behalf Of Jon Senior
 Sent: 27 January 2009 12:09
 To: r-devel@r-project.org
 Subject: [Rd] Return values from .Call and garbage collection
 
 Hi all,
 
 I'm posting this here as it discusses an issue with an 
 external C library. If it would be better in R-Help, then I'll repost.
 
 I'm using an external library which I've written, which 
 provides a large set of data (500MB in a highly condensed 
 format) and the tools to return values from the data. The 
 functionality has been tested call by call and using valgrind 
 and works fine, with no memory leaks. After retrieval, I 
 process the data in R. A specific function is causing a 
 problem that appears to be related to the garbage collector 
 (judging by symptoms).
 
 In the C code, a Matrix is created using
 
 PROTECT(retVal = allocMatrix(INTSXP, x, y));
 
 Values are written into this matrix using
 
 INTEGER(retVal)[translatedOffset]=z;
 
 where translatedOffset is a conversion from a row/column 
 pair to an offset as shown in R-exts.pdf.
 
 The last two lines of the function call are:
 
 UNPROTECT(1);
 return retVal;
 
 The shared library was compiled with R CMD SHLIB and is 
 called using .Call.
 
 Which returns our completed SEXP object to R where processing 
 continues.
 
 In R, we continue to process the data, replacing -1s with NAs 
 (I couldn't find a way to do that in that would make it back 
 into R), sorting it, and trimming it. All of these operations 
 are carried out on the original data.
 
 If I carry out the processing step by step from the 
 interpreter, everything is fine and the data comes out how I 
 would expect. But when I run the R code to carry out those 
 steps, every now and again (Around 1/5th of the time), the 
 returned data is garbage. I'm expecting to receive a bias per 
 iteration that should be -5 = bias = 5, but for the 
 garbaged data, I'm getting results of the order of 100s of 
 thousands out (eg. -220627.7). If I call the routine which 
 carries out the processing for one iteration from the 
 intepreter, sometimes I get the correct data, sometimes (with 
 the same frequency) I get garbage.
 
 There are two possibilities that I can envisage.
 1) Race condition: R is starting to execute the R code after 
 the .Call before the .Call has returned, thus the data is corrupted.
 2) Garbage collector: the GC is collecting my data between 
 the UNPROTECT(1); call and the assignment to an R variable.
 
 The created matrices can be large (where x  1000, y  
 10), but the garbage doesn't appear to be related to the 
 size of the matrix.
 
 Any ideas what steps I could take to proceed with this? Or 
 other possibilities than those I've suggested? For reasons of 
 confidentiality I'm unable to release test code, and the 
 large dataset might make testing difficult.
 
 Thanks in advance
 
 -- 
 Jon Senior j...@restlesslemon.co.uk
 
 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel
 

**
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] [Q] R CMD check signals error on code that works from UI

2009-01-15 Thread Sklyar, Oleg (London)
Because there is a % sign, which is stripped out by LaTeX used to build
the help system as a comment. Just look at how your example code is
output -- the string is unterminated because the matching quote is
masked by % latex comment

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
oskl...@maninvestments.com 

 -Original Message-
 From: r-devel-boun...@r-project.org 
 [mailto:r-devel-boun...@r-project.org] On Behalf Of Paul Roebuck
 Sent: 15 January 2009 17:50
 To: R Development Mailing List
 Subject: [Rd] [Q] R CMD check signals error on code that works from UI
 
 Add the following to example section of a dot-Rd manpage:
 
 ## :WHY: The following kills R CMD check but runs fine on console.
 foos - c(aaa, bbb, ccc)
 cat(sapply(foos,
function(foo) {
sprintf(name: %-18s upper: %s\n,
foo,
toupper(foo))
}), sep=)
 
 
 R CMD check package stops with error:
 
 ...
 * checking examples ... ERROR
 Running examples in 'package-Ex.R' failed.
 The error most likely occurred in:
...
 
  ## :WHY: The following kills R CMD check but runs fine on console.
  foos - c(aaa, bbb, ccc)
  cat(sapply(foos,
 +function(foo) {
 +sprintf(name:
 +foo,
 +toupper(foo))
 +}), sep=)
 +
 +
 +
 + cleanEx(); nameEx(sc80-registerNormalizationMethod)
 Error: unexpected string constant in:
 
 cleanEx(); nameEx(
 Execution halted
 
 
 Yet on console, it provides the expected:
 
 name: aaaupper: AAA
 name: bbbupper: BBB
 name: cccupper: CCC
 
 
 How do I work around this for manpage?
 
 
 --
 SIGSIG -- signature too long (core dumped)
 
 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel
 

**
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] particulars of importing/loading libraries

2009-01-14 Thread Sklyar, Oleg (London)
Sorry Simon, you are right. I tried to recreate a problem that I had
with other packages where the packages were added to Depends but made a
mistake. However the problem remains if I do the following.

Added: pack1 to Depends of pack2. Now I create pack3 with the following
contents: it does not import pack1 directly, nor depends on it. It
rather imports pack2 and depends on pack2. I then expect the
functionality of pack1 to be available still if I only load pack3. But I
now get errors with pack3 calling the function from pack1. Does this
mean I need to import and depend on pack1 and methods explicitly in
pack3. I.e. do I have to import and depend on ALL the packages that may
be in use, even if they are imported by other that I depend on and
import:

 pack3: DESCRIPTION -

Package: pack3
Version: 0.0.1
Date: 12 Jan 2009
Title: pack1 to test S3/S4 methods compatibility
Author:  Oleg Sklyar
Depends: R (= 2.7.1), pack2
Maintainer: Oleg Sklyar oskl...@maninvestments.com
Description: pack3
LazyLoad: yes
License: Proprietary
URL: http://www.maninvestments.com
LazyLoad: no

 pack3: NAMESPACE --
import(pack2)
exportPattern(^[^\\.])

 pack3: posix.R --
testPosix2 = function() {
z = as.POSIXct(testPosixVal)
print(z)
print(class(z))
z
}

Note, that the above function is the same as in pack2, just a different
name.


*** R 2.9.0 (svn -r 46585) [/share/research/R-devel/20081002/lib64/R]
***
 library(pack3)
Loading required package: pack2
Loading required package: pack1
 as.POSIXct(pack1::testPosixVal)
[1] 2009-01-13 15:29:50 UTC
 testPosxi() ## called from pack2
[1] 2009-01-13 15:29:50 UTC
[1] POSIXt  POSIXct
[1] 2009-01-13 15:29:50 UTC
 testPosix2() ## called from pack3
Error in as.POSIXct.default(testPosixVal) : 
  do not know how to convert 'testPosixVal' to class POSIXlt




Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
oskl...@maninvestments.com 

 -Original Message-
 From: Simon Urbanek [mailto:simon.urba...@r-project.org] 
 Sent: 14 January 2009 01:51
 To: Sklyar, Oleg (London)
 Cc: r-devel@r-project.org
 Subject: Re: [Rd] particulars of importing/loading libraries
 
 Oleg,
 
 On Jan 13, 2009, at 11:00 , Sklyar, Oleg (London) wrote:
 
  Dear List:
 
  Sorry for posting maybe a trivial question, but I have a basic
  understanding problem. If I have say pack1 and pack2, two R 
 packages,
  and pack2 depends on and imports pack1 fully (as in the 
 code below),  
  is
  there a way to make all the functionality of pack1 available for the
  global and other environments (not only for the functions 
 called from
  withing pack2) by loading pack2 only? I thought if pack2 
 depends on  
  and
  imports pack1 and essentially reexports everything, one 
 should get the
  full functionality simply by loading pack2. This does not 
 seem to be  
  the
  case or I am missing something trivial in my NAMESPACE/DESCRIPTION
  files?
 
  If this is documented in Writing R Extensions, I would be thankful  
  for a
  page number and maybe a quick fix in my example below as so 
 far I have
  not been able to find a clear explanation.
 
  The problem can be illustrated by the following simple 
 example (this  
  is
  a simple code for 2 packages, pack1 and pack2; plus an example).
 
 
 if you bothered to use R CMD check you would find your bug right away:
 * checking package dependencies ... ERROR
 Namespace dependencies not required:
pack1
 
 You simply forgot to add pack1 to the Depends: line - that's 
 all. Once  
 you fix that, you'll see what happens:
 
   library(pack2)
 Loading required package: pack1
   as.POSIXct(pack1::testPosixVal)
 [1] 2009-01-14 01:38:08 UTC
 
 Cheers,
 S
 
 
  Thank you for your replies.
 
  Dr Oleg Sklyar
  Research Technologist
  AHL / Man Investments Ltd
  +44 (0)20 7144 3107
  oskl...@maninvestments.com
 
  --- pack1: DESCRIPTION --
  Package: pack1
  Version: 0.0.1
  Date: 12 Jan 2009
  Title: pack1 to test S3/S4 methods compatibility
  Author:  Oleg Sklyar
  Depends: R (= 2.7.1), methods
  Maintainer: Oleg Sklyar oskl...@maninvestments.com
  Description: pack1
  LazyLoad: yes
  License: Proprietary
  URL: http://www.maninvestments.com
  LazyLoad: no
 
  --- pack1: NAMESPACE --
  import(methods)
  exportPattern(^[^\\.])
  exportClasses(posixTime)
  exportMethods(as.POSIXct)
 
  --- pack1: posix.R --
  setClass(posixTime, numeric)
 
  setGeneric(as.POSIXct)
  setMethod(as.POSIXct, signature(x=posixTime),
 function(x, tz) {
 z = x...@.data
 attr(z,class) = c(POSIXt, POSIXct)
 attr(z,tzone) = UTC
 z
 }
  )
 
  testPosixVal = new(posixTime, as.numeric(Sys.time()))
 
  --- pack2: DESCRIPTION
  Package: pack2
  Version: 0.0.1
  Date: 12 Jan 2009
  Title: pack2 to test S3/S4 methods compatibility
  Author:  Oleg Sklyar
  Depends: R (= 2.7.1), methods
  Maintainer: Oleg Sklyar oskl...@maninvestments.com
  Description: pack2
  LazyLoad: yes
  License: Proprietary
  URL

Re: [Rd] particulars of importing/loading libraries

2009-01-14 Thread Sklyar, Oleg (London)
Thank you Simon.

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
oskl...@maninvestments.com 

 -Original Message-
 From: Simon Urbanek [mailto:simon.urba...@r-project.org] 
 Sent: 14 January 2009 16:11
 To: Sklyar, Oleg (London)
 Cc: r-devel@r-project.org
 Subject: Re: [Rd] particulars of importing/loading libraries
 
 
 On Jan 14, 2009, at 10:52 , Sklyar, Oleg (London) wrote:
 
  Well, this is very reasonable and this is how it should be I would  
  say. If it was consistent, there would be no problem as they would  
  be easy to nail down. However, the problem is now that if I load  
  pack3 only (which imports pack2 only) then as.POSIXct 
 exported from  
  pack1 is NOT available for functions in pack3,
 
 Because pack3 didn't request it.
 
 
  but is available for calls from the global env (see example 
 below).  
  It is obviously available for calls from functions in pack2 
 as there  
  it is imported directly. Although, why also testPosix() of 
 pack2 is  
  then available for calls from the global env as it was only loaded  
  as import for pack3?
 
 
 Global environment is not encapsulated - you have access to anything  
 that has been attached - sort of implicitly importing anything that  
 has even been [exported and] attached (there is really no concept of  
 importing for the global environment, but the effect is 
 analogous).  
 This is a conceptual difference of the interactive use vs package  
 code. Unlike package code you don't know in advance what you will be  
 doing when you're working interactively, so I think it makes 
 sense to  
 assume that everything is implicitly imported.
 
 Cheers,
 S
 
 
  In my understanding if pack3 does not depend on pack1 directly,
  functionality of pack1 should not be available anywhere apart from
  functions called from pack2 as well as functions in pack2 should  
  only be
  available for calls by functions in pack3 but not in the 
 global env...
  The semantics seems to be broken here, is it not?
 
  library(pack3)
  Loading required package: pack2
  Loading required package: pack1
  testPosix() ## from pack2
  [1] 2009-01-13 15:29:50 UTC
  [1] POSIXt  POSIXct
  [1] 2009-01-13 15:29:50 UTC
  testPosix2()
  Error in as.POSIXct.default(testPosixVal) :
   do not know how to convert 'testPosixVal' to class POSIXlt
  as.POSIXct(pack1::testPosixVal)
  [1] 2009-01-13 15:29:50 UTC
 
 
 
  Dr Oleg Sklyar
  Research Technologist
  AHL / Man Investments Ltd
  +44 (0)20 7144 3107
  oskl...@maninvestments.com
 
  -Original Message-
  From: Simon Urbanek [mailto:simon.urba...@r-project.org]
  Sent: 14 January 2009 15:38
  To: Sklyar, Oleg (London)
  Cc: r-devel@r-project.org
  Subject: Re: [Rd] particulars of importing/loading libraries
 
 
  On Jan 14, 2009, at 4:24 , Sklyar, Oleg (London) wrote:
 
  Sorry Simon, you are right. I tried to recreate a problem
  that I had
  with other packages where the packages were added to Depends but
  made a mistake. However the problem remains if I do the following.
 
  Added: pack1 to Depends of pack2. Now I create pack3 with the
  following contents: it does not import pack1 directly, nor depends
  on it. It rather imports pack2 and depends on pack2. I then expect
  the functionality of pack1 to be available still if I only
  load pack3.
 
 
  That is semantically not a reasonable requirement. pack3 
 cannot (and
  should not) assume anything about the internals of pack2. If
  it needs
  a function from pack1, it has to import it from pack1. If pack2 re-
  exported as.POSIXct then that would make it part of pack2's
  interface
  and then you're free to just depend on pack2.
 
  Cheers,
  S
 
 
 
  But I
  now get errors with pack3 calling the function from 
 pack1. Does this
  mean I need to import and depend on pack1 and methods 
 explicitly in
  pack3. I.e. do I have to import and depend on ALL the
  packages that
  may
  be in use, even if they are imported by other that I depend on and
  import:
 
   pack3: DESCRIPTION -
 
  Package: pack3
  Version: 0.0.1
  Date: 12 Jan 2009
  Title: pack1 to test S3/S4 methods compatibility
  Author:  Oleg Sklyar
  Depends: R (= 2.7.1), pack2
  Maintainer: Oleg Sklyar oskl...@maninvestments.com
  Description: pack3
  LazyLoad: yes
  License: Proprietary
  URL: http://www.maninvestments.com
  LazyLoad: no
 
   pack3: NAMESPACE --
  import(pack2)
  exportPattern(^[^\\.])
 
   pack3: posix.R --
  testPosix2 = function() {
z = as.POSIXct(testPosixVal)
print(z)
print(class(z))
z
  }
 
  Note, that the above function is the same as in pack2, just a
  different
  name.
 
 
  *** R 2.9.0 (svn -r 46585)
  [/share/research/R-devel/20081002/lib64/R]
  ***
  library(pack3)
  Loading required package: pack2
  Loading required package: pack1
  as.POSIXct(pack1::testPosixVal)
  [1] 2009-01-13 15:29:50 UTC
  testPosxi() ## called from pack2
  [1] 2009-01-13 15:29:50 UTC
  [1] POSIXt  POSIXct
  [1] 2009-01-13

[Rd] particulars of importing/loading libraries

2009-01-13 Thread Sklyar, Oleg (London)
Dear List:

Sorry for posting maybe a trivial question, but I have a basic
understanding problem. If I have say pack1 and pack2, two R packages,
and pack2 depends on and imports pack1 fully (as in the code below), is
there a way to make all the functionality of pack1 available for the
global and other environments (not only for the functions called from
withing pack2) by loading pack2 only? I thought if pack2 depends on and
imports pack1 and essentially reexports everything, one should get the
full functionality simply by loading pack2. This does not seem to be the
case or I am missing something trivial in my NAMESPACE/DESCRIPTION
files?

If this is documented in Writing R Extensions, I would be thankful for a
page number and maybe a quick fix in my example below as so far I have
not been able to find a clear explanation.

The problem can be illustrated by the following simple example (this is
a simple code for 2 packages, pack1 and pack2; plus an example).

Thank you for your replies.

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
oskl...@maninvestments.com

--- pack1: DESCRIPTION --
Package: pack1
Version: 0.0.1
Date: 12 Jan 2009
Title: pack1 to test S3/S4 methods compatibility
Author:  Oleg Sklyar
Depends: R (= 2.7.1), methods
Maintainer: Oleg Sklyar oskl...@maninvestments.com
Description: pack1
LazyLoad: yes
License: Proprietary
URL: http://www.maninvestments.com
LazyLoad: no

--- pack1: NAMESPACE --
import(methods)
exportPattern(^[^\\.])
exportClasses(posixTime)
exportMethods(as.POSIXct)

--- pack1: posix.R --
setClass(posixTime, numeric)

setGeneric(as.POSIXct)
setMethod(as.POSIXct, signature(x=posixTime),
function(x, tz) {
z = x...@.data
attr(z,class) = c(POSIXt, POSIXct)
attr(z,tzone) = UTC
z
}
)

testPosixVal = new(posixTime, as.numeric(Sys.time()))

--- pack2: DESCRIPTION 
Package: pack2
Version: 0.0.1
Date: 12 Jan 2009
Title: pack2 to test S3/S4 methods compatibility
Author:  Oleg Sklyar
Depends: R (= 2.7.1), methods
Maintainer: Oleg Sklyar oskl...@maninvestments.com
Description: pack2
LazyLoad: yes
License: Proprietary
URL: http://www.maninvestments.com
LazyLoad: no

--- pack2: NAMESPACE --
import(pack1)
exportPattern(^[^\\.])

--- pack2: posix.R --
testPosix = function() {
z = as.POSIXct(testPosixVal)
print(z)
print(class(z))
z
}

-- test code to run from global env, showing problems ---
require(pack2)

## use as.POSIXct imported into pack2 from pack1 to do the conversion in
the fun
testPosix()
#~ [1] 2009-01-13 15:29:50 UTC
#~ [1] POSIXt  POSIXct
#~ [1] 2009-01-13 15:29:50 UTC

## now try using it directly from the global env (pack1 was not
explicitly loaded)
as.POSIXct(pack1::testPosixVal)
#~ Error in as.POSIXct.default(pack1::testPosixVal) : 
#~  do not know how to convert 'pack1::testPosixVal' to class POSIXlt

## now require pack1 explicitly and try again
require(pack1)
as.POSIXct(pack1::testPosixVal)
#~ [1] 2009-01-13 15:29:50 UTC


**
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] particulars of importing/loading libraries

2009-01-13 Thread Sklyar, Oleg (London)
I was thinking of this, but this is going to be a pain if a package
imports 5 packs, is being imported by another one, which itself is
imported by yet another one and the only one one would like to load
explicitly is the last down the line. If I do not find a better solution
this is what I probably will have to do, reexport everything. 

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
oskl...@maninvestments.com 

 -Original Message-
 From: Martin Morgan [mailto:mtmor...@fhcrc.org] 
 Sent: 13 January 2009 16:31
 To: Sklyar, Oleg (London)
 Cc: r-devel@r-project.org
 Subject: Re: [Rd] particulars of importing/loading libraries
 
 Hi Oleg --
 
 Sklyar, Oleg (London) oskl...@maninvestments.com writes:
 
  Dear List:
 
  Sorry for posting maybe a trivial question, but I have a basic
  understanding problem. If I have say pack1 and pack2, two R 
 packages,
  and pack2 depends on and imports pack1 fully (as in the 
 code below), is
  there a way to make all the functionality of pack1 available for the
  global and other environments (not only for the functions 
 called from
  withing pack2) by loading pack2 only? I thought if pack2 
 depends on and
  imports pack1 and essentially reexports everything, one 
 should get the
  full functionality simply by loading pack2. This does not 
 seem to be the
  case or I am missing something trivial in my NAMESPACE/DESCRIPTION
  files?
 
 I think that exportPattern does a simple ls() on the environment of
 the package name space. The imported symbols are not defined in that
 environment, but (I think) in a variable .__NAMESPACE__. and so are
 not discovered.  Arguably, exportPattern (and friends) should be
 smarter. Pragmatically, you need to re-export imported symbols
 explicitly. I haven't worked this through entirely, and could be
 wrong...
 
 Martin
 
  If this is documented in Writing R Extensions, I would be 
 thankful for a
  page number and maybe a quick fix in my example below as so 
 far I have
  not been able to find a clear explanation.
 
  The problem can be illustrated by the following simple 
 example (this is
  a simple code for 2 packages, pack1 and pack2; plus an example).
 
  Thank you for your replies.
 
  Dr Oleg Sklyar
  Research Technologist
  AHL / Man Investments Ltd
  +44 (0)20 7144 3107
  oskl...@maninvestments.com
 
  --- pack1: DESCRIPTION --
  Package: pack1
  Version: 0.0.1
  Date: 12 Jan 2009
  Title: pack1 to test S3/S4 methods compatibility
  Author:  Oleg Sklyar
  Depends: R (= 2.7.1), methods
  Maintainer: Oleg Sklyar oskl...@maninvestments.com
  Description: pack1
  LazyLoad: yes
  License: Proprietary
  URL: http://www.maninvestments.com
  LazyLoad: no
 
  --- pack1: NAMESPACE --
  import(methods)
  exportPattern(^[^\\.])
  exportClasses(posixTime)
  exportMethods(as.POSIXct)
 
  --- pack1: posix.R --
  setClass(posixTime, numeric)
 
  setGeneric(as.POSIXct)
  setMethod(as.POSIXct, signature(x=posixTime),
  function(x, tz) {
  z = x...@.data
  attr(z,class) = c(POSIXt, POSIXct)
  attr(z,tzone) = UTC
  z
  }
  )
 
  testPosixVal = new(posixTime, as.numeric(Sys.time()))
 
  --- pack2: DESCRIPTION 
  Package: pack2
  Version: 0.0.1
  Date: 12 Jan 2009
  Title: pack2 to test S3/S4 methods compatibility
  Author:  Oleg Sklyar
  Depends: R (= 2.7.1), methods
  Maintainer: Oleg Sklyar oskl...@maninvestments.com
  Description: pack2
  LazyLoad: yes
  License: Proprietary
  URL: http://www.maninvestments.com
  LazyLoad: no
 
  --- pack2: NAMESPACE --
  import(pack1)
  exportPattern(^[^\\.])
 
  --- pack2: posix.R --
  testPosix = function() {
  z = as.POSIXct(testPosixVal)
  print(z)
  print(class(z))
  z
  }
 
  -- test code to run from global env, showing problems ---
  require(pack2)
 
  ## use as.POSIXct imported into pack2 from pack1 to do the 
 conversion in
  the fun
  testPosix()
  #~ [1] 2009-01-13 15:29:50 UTC
  #~ [1] POSIXt  POSIXct
  #~ [1] 2009-01-13 15:29:50 UTC
 
  ## now try using it directly from the global env (pack1 was not
  explicitly loaded)
  as.POSIXct(pack1::testPosixVal)
  #~ Error in as.POSIXct.default(pack1::testPosixVal) : 
  #~  do not know how to convert 'pack1::testPosixVal' to 
 class POSIXlt
 
  ## now require pack1 explicitly and try again
  require(pack1)
  as.POSIXct(pack1::testPosixVal)
  #~ [1] 2009-01-13 15:29:50 UTC
 
 
  
 **
  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
 
 -- 
 Martin Morgan
 Computational Biology / Fred Hutchinson Cancer Research Center
 1100 Fairview Ave. N.
 PO Box 19024 Seattle, WA 98109
 
 Location: Arnold Building M2 B169
 Phone: (206) 667

Re: [Rd] particulars of importing/loading libraries

2009-01-13 Thread Sklyar, Oleg (London)
So essentially I guess it would be nice to have a way of reexporting
everything in

get(imports,env=pack2:::.__NAMESPACE__.)



Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
oskl...@maninvestments.com 

 -Original Message-
 From: Martin Morgan [mailto:mtmor...@fhcrc.org] 
 Sent: 13 January 2009 16:31
 To: Sklyar, Oleg (London)
 Cc: r-devel@r-project.org
 Subject: Re: [Rd] particulars of importing/loading libraries
 
 Hi Oleg --
 
 Sklyar, Oleg (London) oskl...@maninvestments.com writes:
 
  Dear List:
 
  Sorry for posting maybe a trivial question, but I have a basic
  understanding problem. If I have say pack1 and pack2, two R 
 packages,
  and pack2 depends on and imports pack1 fully (as in the 
 code below), is
  there a way to make all the functionality of pack1 available for the
  global and other environments (not only for the functions 
 called from
  withing pack2) by loading pack2 only? I thought if pack2 
 depends on and
  imports pack1 and essentially reexports everything, one 
 should get the
  full functionality simply by loading pack2. This does not 
 seem to be the
  case or I am missing something trivial in my NAMESPACE/DESCRIPTION
  files?
 
 I think that exportPattern does a simple ls() on the environment of
 the package name space. The imported symbols are not defined in that
 environment, but (I think) in a variable .__NAMESPACE__. and so are
 not discovered.  Arguably, exportPattern (and friends) should be
 smarter. Pragmatically, you need to re-export imported symbols
 explicitly. I haven't worked this through entirely, and could be
 wrong...
 
 Martin
 
  If this is documented in Writing R Extensions, I would be 
 thankful for a
  page number and maybe a quick fix in my example below as so 
 far I have
  not been able to find a clear explanation.
 
  The problem can be illustrated by the following simple 
 example (this is
  a simple code for 2 packages, pack1 and pack2; plus an example).
 
  Thank you for your replies.
 
  Dr Oleg Sklyar
  Research Technologist
  AHL / Man Investments Ltd
  +44 (0)20 7144 3107
  oskl...@maninvestments.com
 
  --- pack1: DESCRIPTION --
  Package: pack1
  Version: 0.0.1
  Date: 12 Jan 2009
  Title: pack1 to test S3/S4 methods compatibility
  Author:  Oleg Sklyar
  Depends: R (= 2.7.1), methods
  Maintainer: Oleg Sklyar oskl...@maninvestments.com
  Description: pack1
  LazyLoad: yes
  License: Proprietary
  URL: http://www.maninvestments.com
  LazyLoad: no
 
  --- pack1: NAMESPACE --
  import(methods)
  exportPattern(^[^\\.])
  exportClasses(posixTime)
  exportMethods(as.POSIXct)
 
  --- pack1: posix.R --
  setClass(posixTime, numeric)
 
  setGeneric(as.POSIXct)
  setMethod(as.POSIXct, signature(x=posixTime),
  function(x, tz) {
  z = x...@.data
  attr(z,class) = c(POSIXt, POSIXct)
  attr(z,tzone) = UTC
  z
  }
  )
 
  testPosixVal = new(posixTime, as.numeric(Sys.time()))
 
  --- pack2: DESCRIPTION 
  Package: pack2
  Version: 0.0.1
  Date: 12 Jan 2009
  Title: pack2 to test S3/S4 methods compatibility
  Author:  Oleg Sklyar
  Depends: R (= 2.7.1), methods
  Maintainer: Oleg Sklyar oskl...@maninvestments.com
  Description: pack2
  LazyLoad: yes
  License: Proprietary
  URL: http://www.maninvestments.com
  LazyLoad: no
 
  --- pack2: NAMESPACE --
  import(pack1)
  exportPattern(^[^\\.])
 
  --- pack2: posix.R --
  testPosix = function() {
  z = as.POSIXct(testPosixVal)
  print(z)
  print(class(z))
  z
  }
 
  -- test code to run from global env, showing problems ---
  require(pack2)
 
  ## use as.POSIXct imported into pack2 from pack1 to do the 
 conversion in
  the fun
  testPosix()
  #~ [1] 2009-01-13 15:29:50 UTC
  #~ [1] POSIXt  POSIXct
  #~ [1] 2009-01-13 15:29:50 UTC
 
  ## now try using it directly from the global env (pack1 was not
  explicitly loaded)
  as.POSIXct(pack1::testPosixVal)
  #~ Error in as.POSIXct.default(pack1::testPosixVal) : 
  #~  do not know how to convert 'pack1::testPosixVal' to 
 class POSIXlt
 
  ## now require pack1 explicitly and try again
  require(pack1)
  as.POSIXct(pack1::testPosixVal)
  #~ [1] 2009-01-13 15:29:50 UTC
 
 
  
 **
  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
 
 -- 
 Martin Morgan
 Computational Biology / Fred Hutchinson Cancer Research Center
 1100 Fairview Ave. N.
 PO Box 19024 Seattle, WA 98109
 
 Location: Arnold Building M2 B169
 Phone: (206) 667-2793
 

**
Please consider the environment before printing this email or its attachments.
The contents of this email are for the named addressees

Re: [Rd] handling a matrix and .C

2008-12-01 Thread Sklyar, Oleg (London)
You should not have started with R/C API without reading this (first
link in google): Writing R Extensions. For your particular question
you want pages 72+ and sections 5.9.3 and 5.9.4, possibly further as
well

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
[EMAIL PROTECTED] 

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Wilm Schumacher
 Sent: 24 November 2008 18:59
 To: r-devel@r-project.org
 Subject: [Rd] handling a matrix and .C
 
 Hello R-devel,
 
 I want to write extensions for R in C (maybe C++ and Fortran 
 later) and it works fine, but there is one problem, which I 
 cannot solve (in my view).
 
 I want to handle a matrix from R in C. For arrays there is 
 as.double(...), but nothing for a matrix.
 
 I searched a while, but didn't find something.
 
 Last I looked at the source code of e1071 and of the core 
 itself and recognized (I hope I understood this), that you 
 (and the e1071 people) use as.double() and give .C an 
 array and one have to parse the matrix again in the C function.
 
 This sounds a little complicate. Isn't there another way? A 
 more adapted way?
 
 Greetings
 
 Wilm
 
 ps: I joined the R-devel list, but didn't get an confirmation 
 mail. I hope this is normal
 --
 
 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel
 

**
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


[Rd] POSIXlt getting sec element at 60 when converting from POSIXct

2008-10-14 Thread Sklyar, Oleg (London)
In some cases rounding problems lead to creation of logically incorrect
times in POSIXlt when converting from POSIXct.

## everything works fine for the following values:
x = c(1223972160.0, 1223982660.0, 1223994660.)
## adding 0s for the epoch
x = x + as.POSIXct(1970-01-01 00:00) -
as.numeric(as.POSIXct(1970-01-01 00:00))
x
## [1] 2008-10-14 09:16:00 BST 2008-10-14 12:11:00 BST
## [3] 2008-10-14 15:31:00 BST

Now, numbers that look the same but originate from some calculations
lead to the following weirdness in POSIXlt. Sorry you will not be able
to reproduce as it is impossible to reproduce the same rounding:

 as.character(as.numeric(t1))
[1] 1223972160.0 1223982660.0 1223994660.0
 class(t1)
[1] POSIXt  POSIXct
## here we get a second less due to rounding errors somewhere, not too
bad
 t1
[1] 2008-10-14 09:15:59 BST 2008-10-14 12:10:59 BST
[3] 2008-10-14 15:30:59 BST
 t2 = as.POSIXlt(t1)
 t2  
[1] 2008-10-14 09:15:59 BST 2008-10-14 12:10:59 BST
[3] 2008-10-14 15:30:59 BST

## however here we do get a real problem
 t2$sec
[1] 60 60 60
## and here as well
 format(t2, %Y-%m-%d %H:%M:%OS3)
[1] 2008-10-14 09:15:60.000 2008-10-14 12:10:60.000
[3] 2008-10-14 15:30:60.000
 format(t1, %Y-%m-%d %H:%M:%OS3)
[1] 2008-10-14 09:15:60.000 2008-10-14 12:10:60.000
[3] 2008-10-14 15:30:60.000

Everything is back to normal with applying round (we are anyway limited
to 15 digits):
 t3 = round(as.numeric(t1),5) + .origin
 t3
[1] 2008-10-14 09:16:00 BST 2008-10-14 12:11:00 BST
[3] 2008-10-14 15:31:00 BST

 sessionInfo()
R version 2.9.0 Under development (unstable) (2008-09-30 r46585) 
x86_64-unknown-linux-gnu 

locale:
C

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

[8] base 

other attached packages:
[1] AHLFinance_0.1.54  AHLDBConn_0.2.3ROracle_0.5-9  DBI_0.2-4

[5] RODBC_1.2-3AHLNagLib_0.1.3AHLCalendar_0.2.59
AHLBase_0.1.25

loaded via a namespace (and not attached):
[1] tools_2.9.0

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
[EMAIL PROTECTED]

**
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] Extract method for a new class

2008-09-22 Thread Sklyar, Oleg (London)
You will need to define several for different combinations of i and j
types e.g. ANY,missing; ANY,ANY; missing,ANY or possibly for types like
integer, character and logical more or less in the following way:

setMethod([, signature(x=haplogList, i=ANY,j=ANY),
function(x, i, j, ..., drop=TRUE) {
## do whatever you want here; your class is not derived
from a list
## so we cannot use NextMethod
}
)

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
[EMAIL PROTECTED] 

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Coster, Albart
 Sent: 19 September 2008 16:00
 To: r-devel@r-project.org
 Subject: [Rd] Extract method for a new class
 
 Dear list,
 
 I am trying to write a package for simulating meioses in R. 
 We defined a class 'haplotype' which contains the basic units 
 of our simulation:
 
 setClass(haplotype,representation(snp = numeric,qtl = list,
 hID = numeric,phID0 = 
 numeric,phID1 = numeric),
 prototype = list(hID = 
 0,phID0 = NaN,phID1 = NaN))
 
 In addition, we define a class 'haploList', which is just a 
 list of haplotypes:
 
 setClass(haploList,contains = list,representation(genDist 
 = numeric,roundDec = integer))
 
 Most things work fine, but when subsetting a haploList object 
 an object of class list is returned. I realize that I need to 
 write a function for subsetting this new object, and tried to 
 find the code for '[.listof' or something similar could not 
 find it, probably due to a suboptimal understanding of how it 
 is organized. 
 
 My question is, how could I define a extraction function for 
 my new class that uses all the existing functionality of the 
 Extract function for list? 
 
 Thanks in advance,
 
 Albart Coster
 


**
The contents of this email are for the named addressee(s...{{dropped:22}}

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


[Rd] 'xtfrm' performance (influences 'order' performance) in R devel

2008-09-09 Thread Sklyar, Oleg (London)
Hello everybody,

it looks like the presense of some (do know know which) S4 methods for a
given S4 class degrades the performance of xtfrm (used in 'order' in new
R-devel) by a factor of millions. This is for classes that ARE derived
from numeric directly and thus should be quite trivial to convert to
numeric.

Consider the following example:

setClass(TimeDateBase, 
representation(numeric, mode=character),
prototype(mode=posix)
)
setClass(TimeDate,
representation(TimeDateBase, tzone=character),
prototype(tzone=London)
)
x = new(TimeDate, 1220966224 + runif(1e5))

system.time({ z = order(x) })
##  system.time({ z = order(x) })
##   user  system elapsed 
##  0.048   0.000   0.048 

getClass(TimeDate)
## Class TimeDate

## Slots:

## Name:  .Data tzone  mode
## Class:   numeric character character

## Extends: 
## Class TimeDateBase, directly
## Class numeric, by class TimeDateBase, distance 2
## Class vector, by class TimeDateBase, distance 3


Now, if I load a library that not only defines these same classes, but
also a bunch of methods for those, then I have the following result:

library(AHLCalendar)
x = now() + runif(1e5) ## just random times in POSIXct format
x[1:5]
## TimeDate [posix] object in 'Europe/London' of length 5:
## [1] 2008-09-09 14:19:35.218 2008-09-09 14:19:35.672
## [3] 2008-09-09 14:19:35.515 2008-09-09 14:19:35.721
## [5] 2008-09-09 14:19:35.657

 system.time({ z = order(x) })


Enter a frame number, or 0 to exit   

 1: system.time({
 2: order(x)
 3: lapply(z, function(x) if (is.object(x)) xtfrm(x) else x)
 4: FUN(X[[1]], ...)
 5: xtfrm(x)
 6: xtfrm.default(x)
 7: as.vector(rank(x, ties.method = min, na.last = keep))
 8: rank(x, ties.method = min, na.last = keep)
 9: switch(ties.method, average = , min = , max =
.Internal(rank(x[!nas], ties.
10: .gt(c(1220966375.21811, 1220966375.67217, 1220966375.51470,
1220966375.7211
11: x[j]
12: x[j]

Selection: 0
Timing stopped at: 47.618 13.791 66.478 

At the same time:

system.time({ z = as.numeric(x) }) ## same as [EMAIL PROTECTED]
##   user  system elapsed 
##  0.001   0.000   0.001 

The only difference between the two is that I have the following methods
defined for TimeDate (full listing below). 

Any idea why this could be happenning. And yes, it is down to xtfrm
function, 'order' was just a place where the problem occured. Should
xtfrm function be smarter with respect to classes that are actually
derived from 'numeric'?

 showMethods(class=TimeDate)
Function: + (package base)
e1=TimeDate, e2=TimeDate
e1=TimeDate, e2=numeric
(inherited from: e1=TimeDateBase, e2=numeric)

Function: - (package base)
e1=TimeDate, e2=TimeDate

Function: Time (package AHLCalendar)
x=TimeDate

Function: TimeDate (package AHLCalendar)
x=TimeDate

Function: TimeDate- (package AHLCalendar)
x=TimeSeries, value=TimeDate

Function: TimeSeries (package AHLCalendar)
x=data.frame, ts=TimeDate
x=matrix, ts=TimeDate
x=numeric, ts=TimeDate

Function: [ (package base)
x=TimeDate, i=POSIXt, j=missing
x=TimeDate, i=Time, j=missing
x=TimeDate, i=TimeDate, j=missing
x=TimeDate, i=integer, j=missing
(inherited from: x=TimeDateBase, i=ANY, j=missing)
x=TimeDate, i=logical, j=missing
(inherited from: x=TimeDateBase, i=ANY, j=missing)
x=TimeSeries, i=TimeDate, j=missing
x=TimeSeries, i=TimeDate, j=vector

Function: [- (package base)
x=TimeDate, i=ANY, j=ANY, value=ANY
x=TimeDate, i=ANY, j=ANY, value=numeric
x=TimeDate, i=missing, j=ANY, value=ANY
x=TimeDate, i=missing, j=ANY, value=numeric

Function: add (package AHLCalendar)
x=TimeDate

Function: addMonths (package AHLCalendar)
x=TimeDate

Function: addYears (package AHLCalendar)
x=TimeDate

Function: align (package AHLCalendar)
x=TimeDate, to=character
x=TimeDate, to=missing

Function: as.POSIXct (package base)
x=TimeDate

Function: as.POSIXlt (package base)
x=TimeDate

Function: coerce (package methods)
from=TimeDate, to=TimeDateBase

Function: coerce- (package methods)
from=TimeDate, to=numeric

Function: dates (package AHLCalendar)
x=TimeDate

Function: format (package base)
x=TimeDate

Function: fxFwdDate (package AHLCalendar)
x=TimeDate, country=character

Function: fxSettleDate (package AHLCalendar)
x=TimeDate, country=character

Function: holidays (package AHLCalendar)
x=TimeDate

Function: index (package AHLCalendar)
x=TimeDate, y=POSIXt
x=TimeDate, y=Time
x=TimeDate, y=TimeDate

Function: initialize (package methods)
.Object=TimeDate
(inherited from: .Object=ANY)

Function: leapYear (package AHLCalendar)
x=TimeDate

Function: mday (package AHLCalendar)
x=TimeDate

Function: mode (package base)
x=TimeDate
(inherited from: x=TimeDateBase)

Function: mode- (package base)
x=TimeDate, value=character
(inherited from: x=TimeDateBase, value=character)

Function: month (package AHLCalendar)
x=TimeDate

Function: pretty (package base)
x=TimeDate

Function: prettyFormat (package AHLCalendar)
x=TimeDate, munit=character
x=TimeDate, 

Re: [Rd] 'xtfrm' performance (influences 'order' performance) in R devel

2008-09-09 Thread Sklyar, Oleg (London)
Thanks for a quick reply, I was thinking of [ methods myself, but there
are so many of them. I only tested [(x=TimeDate,i=TimeDate,j=missing),
which is a completely non-standard one. It did not seem to have any
effect though. 

I was thinking of writing the 'order' method and will experiment with
getting the one for xtfrm. However, it seems reasonable for the default
xtfrm to check if the object is inherited from a vector and in that case
simply returning the .Data slot? This would solve this and similar cases
immediately:

if (inherits(x,vector)) return(as.vector([EMAIL PROTECTED]))

BTW, generally, xtfrm.default calls 'rank' and it is not clear why rank
should work for a generic S4 object... this is essentially where the
problem is.


On a side note, a week ago I submitted a patch for the plot.default to
Rd, but nobody reacted (I checked the most recent patched and devel as
well) -- it is really an ugly bug (e.g
plot(1:5,1:5,xlim=c(-10,10),ylim=c(-8,3))  ) and the trivial patch fixes
it. Would be grateful if somebody from R-core checks it up. Meanwhile I
patch the graphics library before compiling R, which is not the best
solution. Here is the patch for src/library/graphics/plot.R

70,71c70,71
   localAxis(if(is.null(y)) xy$x else x, side = 1, ...)
   localAxis(if(is.null(y))  x   else y, side = 2, ...)
---
 localAxis(xlim, side = 1, ...)
 localAxis(ylim, side = 2, ...)


Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
[EMAIL PROTECTED] 

 -Original Message-
 From: John Chambers [mailto:[EMAIL PROTECTED] 
 Sent: 09 September 2008 15:11
 To: Sklyar, Oleg (London)
 Cc: R-devel@r-project.org
 Subject: Re: [Rd] 'xtfrm' performance (influences 'order' 
 performance) in R devel
 
 No definitive answers, but here are a few observations.
 
 In the call to order() code, I notice that you have dropped 
 into the branch
 if (any(unlist(lapply(z, is.object
 where the alternative in your case would seem to have been 
 going directly to the internal code.
 
 You can consider a method for xtfrm(), which would help but 
 won't get you completely back to a trivial computation.  
 Alternatively,  order() should be eligible for the new 
 mechanism of defining methods for 
 
 (Individual existing methods may not be the issue, and one 
 can't infer anything definite from the evidence given,  but a 
 plausible culprit is the [ method.  Because [] expressions 
 appear so often, it's always chancy to define a nontrivial 
 method for this function.)
 
 John
 
 Sklyar, Oleg (London) wrote: 
 
   Hello everybody,
   
   it looks like the presense of some (do know know which) 
 S4 methods for a
   given S4 class degrades the performance of xtfrm (used 
 in 'order' in new
   R-devel) by a factor of millions. This is for classes 
 that ARE derived
   from numeric directly and thus should be quite trivial 
 to convert to
   numeric.
   
   Consider the following example:
   
   setClass(TimeDateBase, 
   representation(numeric, mode=character),
   prototype(mode=posix)
   )
   setClass(TimeDate,
   representation(TimeDateBase, tzone=character),
   prototype(tzone=London)
   )
   x = new(TimeDate, 1220966224 + runif(1e5))
   
   system.time({ z = order(x) })
   ##  system.time({ z = order(x) })
   ##   user  system elapsed 
   ##  0.048   0.000   0.048 
   
   getClass(TimeDate)
   ## Class TimeDate
   
   ## Slots:
   
   ## Name:  .Data tzone  mode
   ## Class:   numeric character character
   
   ## Extends: 
   ## Class TimeDateBase, directly
   ## Class numeric, by class TimeDateBase, distance 2
   ## Class vector, by class TimeDateBase, distance 3
   
   
   Now, if I load a library that not only defines these 
 same classes, but
   also a bunch of methods for those, then I have the 
 following result:
   
   library(AHLCalendar)
   x = now() + runif(1e5) ## just random times in POSIXct format
   x[1:5]
   ## TimeDate [posix] object in 'Europe/London' of length 5:
   ## [1] 2008-09-09 14:19:35.218 2008-09-09 14:19:35.672
   ## [3] 2008-09-09 14:19:35.515 2008-09-09 14:19:35.721
   ## [5] 2008-09-09 14:19:35.657
   
 
 
   system.time({ z = order(x) })
   
 
   
   
   Enter a frame number, or 0 to exit   
   
1: system.time({
2: order(x)
3: lapply(z, function(x) if (is.object(x)) xtfrm(x) else x)
4: FUN(X[[1]], ...)
5: xtfrm(x)
6: xtfrm.default(x)
7: as.vector(rank(x, ties.method = min, na.last = keep))
8: rank(x, ties.method = min, na.last = keep)
9: switch(ties.method, average = , min = , max =
   .Internal(rank(x[!nas], ties.
   10: .gt(c(1220966375.21811

Re: [Rd] 'xtfrm' performance (influences 'order' performance) in R devel

2008-09-09 Thread Sklyar, Oleg (London)
Ha, defined xtfrm for TimeDate, works instantly (xtfrm is already a
method). However, it won't be taken up by order as it is not in the
imported namespace, so order falls back to xtfrm.default.

Moreover, defining order (which is not a method unfortunately, *any
chance of changing this*?):

setGeneric(order)
setMethod(order, TimeDate, 
function (..., na.last = TRUE, decreasing = FALSE) 
order(list(...)[EMAIL PROTECTED],na.last=na.last,
decreasing=decreasing))

does not help either as it won't be taken up, order still calls the
default one, what am I doing wrong?



Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
[EMAIL PROTECTED] 

 -Original Message-
 From: John Chambers [mailto:[EMAIL PROTECTED] 
 Sent: 09 September 2008 15:11
 To: Sklyar, Oleg (London)
 Cc: R-devel@r-project.org
 Subject: Re: [Rd] 'xtfrm' performance (influences 'order' 
 performance) in R devel
 
 No definitive answers, but here are a few observations.
 
 In the call to order() code, I notice that you have dropped 
 into the branch
 if (any(unlist(lapply(z, is.object
 where the alternative in your case would seem to have been 
 going directly to the internal code.
 
 You can consider a method for xtfrm(), which would help but 
 won't get you completely back to a trivial computation.  
 Alternatively,  order() should be eligible for the new 
 mechanism of defining methods for 
 
 (Individual existing methods may not be the issue, and one 
 can't infer anything definite from the evidence given,  but a 
 plausible culprit is the [ method.  Because [] expressions 
 appear so often, it's always chancy to define a nontrivial 
 method for this function.)
 
 John
 
 Sklyar, Oleg (London) wrote: 
 
   Hello everybody,
   
   it looks like the presense of some (do know know which) 
 S4 methods for a
   given S4 class degrades the performance of xtfrm (used 
 in 'order' in new
   R-devel) by a factor of millions. This is for classes 
 that ARE derived
   from numeric directly and thus should be quite trivial 
 to convert to
   numeric.
   
   Consider the following example:
   
   setClass(TimeDateBase, 
   representation(numeric, mode=character),
   prototype(mode=posix)
   )
   setClass(TimeDate,
   representation(TimeDateBase, tzone=character),
   prototype(tzone=London)
   )
   x = new(TimeDate, 1220966224 + runif(1e5))
   
   system.time({ z = order(x) })
   ##  system.time({ z = order(x) })
   ##   user  system elapsed 
   ##  0.048   0.000   0.048 
   
   getClass(TimeDate)
   ## Class TimeDate
   
   ## Slots:
   
   ## Name:  .Data tzone  mode
   ## Class:   numeric character character
   
   ## Extends: 
   ## Class TimeDateBase, directly
   ## Class numeric, by class TimeDateBase, distance 2
   ## Class vector, by class TimeDateBase, distance 3
   
   
   Now, if I load a library that not only defines these 
 same classes, but
   also a bunch of methods for those, then I have the 
 following result:
   
   library(AHLCalendar)
   x = now() + runif(1e5) ## just random times in POSIXct format
   x[1:5]
   ## TimeDate [posix] object in 'Europe/London' of length 5:
   ## [1] 2008-09-09 14:19:35.218 2008-09-09 14:19:35.672
   ## [3] 2008-09-09 14:19:35.515 2008-09-09 14:19:35.721
   ## [5] 2008-09-09 14:19:35.657
   
 
 
   system.time({ z = order(x) })
   
 
   
   
   Enter a frame number, or 0 to exit   
   
1: system.time({
2: order(x)
3: lapply(z, function(x) if (is.object(x)) xtfrm(x) else x)
4: FUN(X[[1]], ...)
5: xtfrm(x)
6: xtfrm.default(x)
7: as.vector(rank(x, ties.method = min, na.last = keep))
8: rank(x, ties.method = min, na.last = keep)
9: switch(ties.method, average = , min = , max =
   .Internal(rank(x[!nas], ties.
   10: .gt(c(1220966375.21811, 1220966375.67217, 1220966375.51470,
   1220966375.7211
   11: x[j]
   12: x[j]
   
   Selection: 0
   Timing stopped at: 47.618 13.791 66.478 
   
   At the same time:
   
   system.time({ z = as.numeric(x) }) ## same as [EMAIL PROTECTED]
   ##   user  system elapsed 
   ##  0.001   0.000   0.001 
   
   The only difference between the two is that I have the 
 following methods
   defined for TimeDate (full listing below). 
   
   Any idea why this could be happenning. And yes, it is 
 down to xtfrm
   function, 'order' was just a place where the problem 
 occured. Should
   xtfrm function be smarter with respect to classes that 
 are actually
   derived from 'numeric'?
   
 
 
   showMethods(class=TimeDate

Re: [Rd] 'xtfrm' performance (influences 'order' performance) in R devel

2008-09-09 Thread Sklyar, Oleg (London)
In fact it all comes back to 'rank', which uses 'order(x[!nas])'
internally. Surprisingly one does not get an infinite recursion: rank -
order - xtfrm - rank - ...

This is obviously only one of possible outcomes, yet it seems to be
happening. Previous implementation of order did not have a reference to
xtfrm and thus would not cause this infinite loop

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
[EMAIL PROTECTED] 

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Sklyar, 
 Oleg (London)
 Sent: 09 September 2008 15:49
 To: John Chambers
 Cc: R-devel@r-project.org
 Subject: Re: [Rd] 'xtfrm' performance (influences 'order' 
 performance) in R devel
 
 Ha, defined xtfrm for TimeDate, works instantly (xtfrm is already a
 method). However, it won't be taken up by order as it is not in the
 imported namespace, so order falls back to xtfrm.default.
 
 Moreover, defining order (which is not a method unfortunately, *any
 chance of changing this*?):
 
 setGeneric(order)
 setMethod(order, TimeDate, 
   function (..., na.last = TRUE, decreasing = FALSE) 
   order(list(...)[EMAIL PROTECTED],na.last=na.last,
 decreasing=decreasing))
 
 does not help either as it won't be taken up, order still calls the
 default one, what am I doing wrong?
 
 
 
 Dr Oleg Sklyar
 Research Technologist
 AHL / Man Investments Ltd
 +44 (0)20 7144 3107
 [EMAIL PROTECTED] 
 
  -Original Message-
  From: John Chambers [mailto:[EMAIL PROTECTED] 
  Sent: 09 September 2008 15:11
  To: Sklyar, Oleg (London)
  Cc: R-devel@r-project.org
  Subject: Re: [Rd] 'xtfrm' performance (influences 'order' 
  performance) in R devel
  
  No definitive answers, but here are a few observations.
  
  In the call to order() code, I notice that you have dropped 
  into the branch
  if (any(unlist(lapply(z, is.object
  where the alternative in your case would seem to have been 
  going directly to the internal code.
  
  You can consider a method for xtfrm(), which would help but 
  won't get you completely back to a trivial computation.  
  Alternatively,  order() should be eligible for the new 
  mechanism of defining methods for 
  
  (Individual existing methods may not be the issue, and one 
  can't infer anything definite from the evidence given,  but a 
  plausible culprit is the [ method.  Because [] expressions 
  appear so often, it's always chancy to define a nontrivial 
  method for this function.)
  
  John
  
  Sklyar, Oleg (London) wrote: 
  
  Hello everybody,
  
  it looks like the presense of some (do know know which) 
  S4 methods for a
  given S4 class degrades the performance of xtfrm (used 
  in 'order' in new
  R-devel) by a factor of millions. This is for classes 
  that ARE derived
  from numeric directly and thus should be quite trivial 
  to convert to
  numeric.
  
  Consider the following example:
  
  setClass(TimeDateBase, 
  representation(numeric, mode=character),
  prototype(mode=posix)
  )
  setClass(TimeDate,
  representation(TimeDateBase, tzone=character),
  prototype(tzone=London)
  )
  x = new(TimeDate, 1220966224 + runif(1e5))
  
  system.time({ z = order(x) })
  ##  system.time({ z = order(x) })
  ##   user  system elapsed 
  ##  0.048   0.000   0.048 
  
  getClass(TimeDate)
  ## Class TimeDate
  
  ## Slots:
  
  ## Name:  .Data tzone  mode
  ## Class:   numeric character character
  
  ## Extends: 
  ## Class TimeDateBase, directly
  ## Class numeric, by class TimeDateBase, distance 2
  ## Class vector, by class TimeDateBase, distance 3
  
  
  Now, if I load a library that not only defines these 
  same classes, but
  also a bunch of methods for those, then I have the 
  following result:
  
  library(AHLCalendar)
  x = now() + runif(1e5) ## just random times in POSIXct format
  x[1:5]
  ## TimeDate [posix] object in 'Europe/London' of length 5:
  ## [1] 2008-09-09 14:19:35.218 2008-09-09 14:19:35.672
  ## [3] 2008-09-09 14:19:35.515 2008-09-09 14:19:35.721
  ## [5] 2008-09-09 14:19:35.657
  

  
  system.time({ z = order(x) })
  
  
  
  
  Enter a frame number, or 0 to exit   
  
   1: system.time({
   2: order(x)
   3: lapply(z, function(x) if (is.object(x)) xtfrm(x) else x)
   4: FUN(X[[1]], ...)
   5: xtfrm(x)
   6: xtfrm.default(x)
   7: as.vector(rank(x, ties.method = min, na.last = keep))
   8: rank(x, ties.method = min, na.last = keep)
   9: switch(ties.method, average = , min = , max =
  .Internal(rank(x[!nas], ties.
  10: .gt(c(1220966375.21811, 1220966375.67217, 1220966375.51470,
  1220966375.7211
  11: x[j]
  12: x[j

Re: [Rd] 'xtfrm' performance (influences 'order' performance) in R devel

2008-09-09 Thread Sklyar, Oleg (London)

Aha, it works if I do

setGeneric(order, signature=...)

However the problem with that is that it generates a warning which I
cannot suppress on install:

Creating a generic for order in package  AHLCalendar
(the supplied definition differs from and overrides the implicit
generic in package base: Signatures differ:  (...), (na.last,
decreasing))

and it generates a warning about masking order from base on load:

  AHLCalendar [0.2.42] (9 Sep 2008). ?AHLCalendar or
vignette('AHLCalendar') to get started

Attaching package: 'AHLCalendar'

The following object(s) are masked from package:base :

 order 

The package exports (excerpt):

exportPattern(^[^\\.])
exportMethods(order)

The reason for these messages is that the signature is different and I
particularly dislike the masking thing (as I cannot predict if it leads
to other problems somewhere). As I understand the current dotsMethods
does not allow mixing dots and other types, so I cannot really define a
matching signature. Is that right? Is there a way around it?

As for the rest, yes, I meant generic and it works nicely for xtfrm. But
as I wrote later, the problem is in 'rank' and rank is not generic so
defining a method would not help in calling a different implementation.

Thanks,
Oleg

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
[EMAIL PROTECTED] 

 -Original Message-
 From: John Chambers [mailto:[EMAIL PROTECTED] 
 Sent: 09 September 2008 16:42
 To: Sklyar, Oleg (London)
 Cc: R-devel@r-project.org
 Subject: Re: [Rd] 'xtfrm' performance (influences 'order' 
 performance) in R devel
 
 Sklyar, Oleg (London) wrote: 
 
   Ha, defined xtfrm for TimeDate, works instantly (xtfrm 
 is already a
   method). However, it won't be taken up by order as it 
 is not in the
   imported namespace, so order falls back to xtfrm.default.
 
 
 By method you mean generic?  xtfrm is an S3 generic.  I'm 
 not clear what happens if you define an S3 method for it.  
 Yes, there is a problem defining an S4 generic  it would be 
 good to deal with that.  Nontrivial, however.
 
 
   
   Moreover, defining order (which is not a method 
 unfortunately, *any
   chance of changing this*?):
   
   setGeneric(order)
   setMethod(order, TimeDate, 
   function (..., na.last = TRUE, decreasing = FALSE) 
   order(list(...)[EMAIL PROTECTED],na.last=na.last,
   decreasing=decreasing))
   
   does not help either as it won't be taken up, order 
 still calls the
   default one, what am I doing wrong?
 
 
 I'm skeptical that this is true.  I did a simple example:
 
  setClass(foo, contains = numeric, representation(flag = 
 logical))
 [1] foo
  xx = new(foo, rnorm(5))
  setGeneric(order, sig = ...)
 Creating a generic for order in package  .GlobalEnv
 (the supplied definition differs from and overrides the 
 implicit generic in package base: Signatures differ:  
 (...), (na.last, decreasing))
 [1] order
  setMethod(order, foo, function (..., na.last = TRUE, 
 decreasing = FALSE){message(Method called); order([EMAIL PROTECTED])})
 [1] order
  order(xx)
 Method called
 [1] 2 4 3 1 5
 
 You do need to be calling order() directly from one of your 
 functions, and have it in your namespace, if your package has one.
 
 
   
   
   
   Dr Oleg Sklyar
   Research Technologist
   AHL / Man Investments Ltd
   +44 (0)20 7144 3107
   [EMAIL PROTECTED] 
   
 
 
   -Original Message-
   From: John Chambers [mailto:[EMAIL PROTECTED] 
   Sent: 09 September 2008 15:11
   To: Sklyar, Oleg (London)
   Cc: R-devel@r-project.org
   Subject: Re: [Rd] 'xtfrm' performance 
 (influences 'order' 
   performance) in R devel
   
   No definitive answers, but here are a few observations.
   
   In the call to order() code, I notice that you 
 have dropped 
   into the branch
   if (any(unlist(lapply(z, is.object
   where the alternative in your case would seem 
 to have been 
   going directly to the internal code.
   
   You can consider a method for xtfrm(), which 
 would help but 
   won't get you completely back to a trivial 
 computation.  
   Alternatively,  order() should be eligible for the new 
   mechanism of defining methods for 
   
   (Individual existing methods may not be the 
 issue, and one 
   can't infer anything definite from the evidence 
 given,  but a 
   plausible culprit is the [ method.  Because 
 [] expressions 
   appear so often, it's always chancy to define a 
 nontrivial 
   method for this function.)
   
   John

[Rd] incorrect ticks in plot(with xlim/ylim) and matplot in R2.7.2, R2.8.0

2008-09-04 Thread Sklyar, Oleg (London)
Dear Martin,

I understand the reasons behind PDF removal, but I actually added a
description of the problem with R2.7+ before... (I cannot select which
email client I use in the office).

Now the problem remains and here is the illustration. The reason for
setting xlim beyond the data range can be e.g. that more data are added
afterwards:

plot(c(-5,5),1:2, xlim=c(-10,10))

R2.6.1 outputs X axis ticks correctly as in:

+--- (-10) - (-5) - (0) - (5) - (10)
---+

R2.8.0 and R2.7.2 patched output X-axis ticks incorrectly as in the
following illustration (well, the ticks are correct, but the plots are
ugly because ticks do not cover the whole range requested):

+- (-6) - (-4) - (-2) - (0) - (2) - (4) - (6)
--+

Also, try the following code in R2.6.1 and R2.7+:

m = matrix(c(-0.033, 0.009, 0.064, 0.050, 0.097,
-0.008, 0.037, 0.070, 0.060, 0.077,
-0.027, 0.051, 0.060, 0.106, 0.049,
-0.068, -0.009, 0.095, 0.091, 0.125,
-0.065, 0.013, 0.062, 0.111, 0.080), ncol=5, byrow=TRUE)

plot(c(-5,5),c(0,10),xlim=c(-10,10),ylim=c(-5,15))
x11(); matplot(m)


Here are the seesionInfo's:

-
R version 2.8.0 Under development (unstable) (2008-08-05 r46234) 
x86_64-unknown-linux-gnu 

locale:
C

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

-
R version 2.7.2 Patched (2008-08-26 r46442) 
x86_64-unknown-linux-gnu 

locale:
C

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

-
R version 2.6.1 (2007-11-26) 
x86_64-unknown-linux-gnu 

locale:
C

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


loaded via a namespace (and not attached):
[1] rcompgen_0.1-17


Dr Oleg Sklyar
Technology Group
Man Investments Ltd
+44 (0)20 7144 3803
[EMAIL PROTECTED] 



**
The contents of this email are for the named addressee(s...{{dropped:22}}

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


[Rd] patch for graphics/R/plot.R that fixes incorrect tick positions

2008-09-04 Thread Sklyar, Oleg (London)
As I haven't got any replies to my earlier posts about incorrect tick
positions in plot and matplot, here is the simplest patch to correct
this issue (it fixes both plot with xlim/ylim and matplot). The plot.R
was unchanged between 2.7 and current R-devel. It would be great if the
patch could be (tested and) applied to both the current patched and the
current devel versions.

70,71c70,71
   localAxis(if(is.null(y)) xy$x else x, side = 1, ...)
   localAxis(if(is.null(y))  x   else y, side = 2, ...)
---
 localAxis(xlim, side = 1, ...)
 localAxis(ylim, side = 2, ...)

It works fine with y given or y NULL, which was an issue before when the
above is.null test was introduced about half a year ago to avoid
conversion to double and thus dropping custom Axis methods. The patched
version was tested with custom time/date Axis methods and works fine, as
well as it works fine with POSIXct objects.

Thanks,
Oleg

Dr Oleg Sklyar
Technology Group
Man Investments Ltd
+44 (0)20 7144 3803
[EMAIL PROTECTED]


**
The contents of this email are for the named addressee(s...{{dropped:22}}

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


[Rd] ugly plots with xlim/ylim exceeding data range (changed since R2.6.1)

2008-09-03 Thread Sklyar, Oleg (London)
The behaviour of the plot function when used with xlim/ylim and the
matplot function as in the following simple example changed between
R2.6.1 and 2.7.0+ producing ugly plots in the new versions. In case of
plot it looks like the pretty function is called with wrong arguments
(i.e. range of supplied data rather than values of xlim and ylim):

m = matrix(c(-0.033, 0.009, 0.064, 0.050, 0.097,
-0.008, 0.037, 0.070, 0.060, 0.077,
-0.027, 0.051, 0.060, 0.106, 0.049,
-0.068, -0.009, 0.095, 0.091, 0.125,
-0.065, 0.013, 0.062, 0.111, 0.080), ncol=5, byrow=TRUE)

pdf(sprintf(R2.%s_SVN_%s.pdf, version$minor, version$svn rev))
plot(c(-5,5),c(0,10),xlim=c(-10,10),ylim=c(-5,15))
matplot(m)
dev.off()

I attached three PDFs with the outputs from R2.6.1 (43537) (which I
consider to be correct), R2.7.2 patched (46442) and R2.8.0 (46234). Just
in case PDFs are removed by the mail server here is the description of
the problem: the one from R2.6.1 plots the axes correctly putting ticks
along the whole axis range even if the data fits just the part of the
range; the ones from 2.7.2 and 2.8.0 put ticks just for the part of the
axis range. In case of plot they cover the range of the data, but with
the requested xlim and ylim they should cover the range of those, and in
case of matplot the range of ticks does not cover the range of data at
all.

Here are the seesionInfo's:

-
R version 2.8.0 Under development (unstable) (2008-08-05 r46234) 
x86_64-unknown-linux-gnu 

locale:
C

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

-
R version 2.7.2 Patched (2008-08-26 r46442) 
x86_64-unknown-linux-gnu 

locale:
C

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

-
R version 2.6.1 (2007-11-26) 
x86_64-unknown-linux-gnu 

locale:
C

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


loaded via a namespace (and not attached):
[1] rcompgen_0.1-17


Dr Oleg Sklyar
Technology Group
Man Investments Ltd
+44 (0)20 7144 3803
[EMAIL PROTECTED]


**
The contents of this email are for the named addressee(s) only.
It contains information which may be confidential and privileged.
If you are not the intended recipient, please notify the sender
immediately, destroy this email and any attachments and do not
otherwise disclose or use them. Email transmission is not a
secure method of communication and Man Investments cannot accept
responsibility for the completeness or accuracy of this email or
any attachments. Whilst Man Investments makes every effort to keep
its network free from viruses, it does not accept responsibility
for any computer virus which might be transferred by way of this
email or any attachments. This email does not constitute a request,
offer, recommendation or solicitation of any kind to buy, subscribe,
sell or redeem any investment instruments or to perform other such
transactions of any kind. Man Investments reserves the right to
monitor, record and retain all electronic communications through
its network to ensure the integrity of its systems, for record
keeping and regulatory purposes. 

Visit us at: www.maninvestments.com

**

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


[Rd] showMethods(plot, printTo=FALSE) fails if printTo set to FALSE

2008-08-20 Thread Sklyar, Oleg (London)
Hi everybody,

any idea why showMethods fails with the following error when printTo is
set to false, i.e. to return the output as a character vector. It works
fine if printTo is left default as seen below. The behaviour is
consistent for any method I tried. stdin() generally works fine on this
system, at least when checked with: x = readLines().

Thanks,
Oleg

 x = showMethods(plot, printTo=FALSE)
Error in cat(file = printTo, sep = , ...) : 
  cannot switch output to stdin

Enter a frame number, or 0 to exit   

1: showMethods(plot, printTo = FALSE)
2: .showMethodsTable(fdef, includeDefs, inherited, classes = classes,
showEmpt
3: doFun(f, p)
4: cf(Function: , func,  (package , pkg, )\n)
5: cat(file = printTo, sep = , ...)

Selection: 0
 x = showMethods(plot)
Function: plot (package graphics)
x=ANY, y=ANY
x=SimResults, y=SimResults
x=SimResults, y=missing
x=TimeDateBase, y=character
x=TimeDateBase, y=data.frameOrMatrix
x=TimeDateBase, y=missing
x=TimeSeries, y=missing

 sessionInfo()
R version 2.8.0 Under development (unstable) (2008-08-05 r46234) 
x86_64-unknown-linux-gnu 

locale:
C

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

[8] base 

other attached packages:

## 64bit RHEL 5


Dr Oleg Sklyar
Technology Group
Man Investments Ltd
+44 (0)20 7144 3803
[EMAIL PROTECTED]


**
The contents of this email are for the named addressee(s...{{dropped:22}}

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


Re: [Rd] showMethods(plot, printTo=FALSE) fails if printTo set to FALSE

2008-08-20 Thread Sklyar, Oleg (London)
Thanks for a good tip.

Dr Oleg Sklyar
Technology Group
Man Investments Ltd
+44 (0)20 7144 3803
[EMAIL PROTECTED] 

 -Original Message-
 From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] 
 Sent: 20 August 2008 13:29
 To: Sklyar, Oleg (London)
 Cc: [EMAIL PROTECTED]
 Subject: Re: [Rd] showMethods(plot, printTo=FALSE) fails if 
 printTo set to FALSE
 
 On Wed, 20 Aug 2008, Sklyar, Oleg (London) wrote:
 
  Hi everybody,
 
  any idea why showMethods fails with the following error 
 when printTo is
  set to false, i.e. to return the output as a character 
 vector. It works
  fine if printTo is left default as seen below. The behaviour is
  consistent for any method I tried. stdin() generally works 
 fine on this
  system, at least when checked with: x = readLines().
 
  Thanks,
  Oleg
 
  x = showMethods(plot, printTo=FALSE)
  Error in cat(file = printTo, sep = , ...) :
   cannot switch output to stdin
 
 This has coerced FALSE to 0, which is connection stdin().  You cannot 
 write to stdin.
 
 I see no sign that printTo = FALSE has been implemented.  You 
 could use a 
 text connection, e.g.
 
 con - textConnection(NULL, open=w)
 x - showMethods(plot, printTo=con)
 textConnectionValue(con)
 close(con)
 
 
  Enter a frame number, or 0 to exit
 
  1: showMethods(plot, printTo = FALSE)
  2: .showMethodsTable(fdef, includeDefs, inherited, classes 
 = classes,
  showEmpt
  3: doFun(f, p)
  4: cf(Function: , func,  (package , pkg, )\n)
  5: cat(file = printTo, sep = , ...)
 
  Selection: 0
  x = showMethods(plot)
  Function: plot (package graphics)
  x=ANY, y=ANY
  x=SimResults, y=SimResults
  x=SimResults, y=missing
  x=TimeDateBase, y=character
  x=TimeDateBase, y=data.frameOrMatrix
  x=TimeDateBase, y=missing
  x=TimeSeries, y=missing
 
  sessionInfo()
  R version 2.8.0 Under development (unstable) (2008-08-05 r46234)
  x86_64-unknown-linux-gnu
 
  locale:
  C
 
  attached base packages:
  [1] datasets  splines   utils stats graphics  
 grDevices methods
 
  [8] base
 
  other attached packages:
 
  ## 64bit RHEL 5
 
 
  Dr Oleg Sklyar
  Technology Group
  Man Investments Ltd
  +44 (0)20 7144 3803
  [EMAIL PROTECTED]
 
 
  
 **
  The contents of this email are for the named 
 addressee(s...{{dropped:22}}
 
  __
  R-devel@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-devel
 
 
 -- 
 Brian D. Ripley,  [EMAIL PROTECTED]
 Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
 University of Oxford, Tel:  +44 1865 272861 (self)
 1 South Parks Road, +44 1865 272866 (PA)
 Oxford OX1 3TG, UKFax:  +44 1865 272595
 


**
The contents of this email are for the named addressee(s...{{dropped:22}}

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


Re: [Rd] Clash between 'Cairo' and 'EBImage' packages on Windows

2008-07-21 Thread Sklyar, Oleg (London)
EBImage is dynamically linked against GTK, which includes cairo
libraries, so those are installed along with GTK. Cairo seems to be
statically linking to libcairo.dll.a. I would assume that if it is
linked statically it should not get confused with a shared library
present elsewhere in the path, but it looks like it does. I have no
solution for that because unlike Cairo I cannot not statically link
EBImage to GTK as it is not one library that I need, but a bunch of
those.

On Linux you won't get this problem as it uses the same centrally
installed Cairo library.

In a way it would be better, if Cairo relied on the gladewin32.sf.net
which normally provides GTK (and thus cairo libraries) for Windows and
linked dynamically, but probably to simplify user installations the
developers wanted to avoid this.

There is not much I can do now about this, but I will follow the thread
if anybody comes up with an idea to change the code if possible

Dr Oleg Sklyar
Technology Group
Man Investments Ltd
+44 (0)20 7144 3803
[EMAIL PROTECTED] 

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Henrik Bengtsson
 Sent: 19 July 2008 19:26
 To: R-devel
 Subject: [Rd] Clash between 'Cairo' and 'EBImage' packages on Windows
 
 Hi,
 
 on Windows XP Pro with R version 2.7.1 Patched (2008-06-27 
 r46012) the 'Cairo' and the 'EBImage' packages does not play 
 well together.
 
 Loading EBImage before Cairo cause the following to happen:
 
 # Rterm --vanilla
  library(EBImage);
  library(Cairo)
 Error in inDL(x, as.logical(local), as.logical(now), ...) :
   unable to load shared library 
 'C:/PROGRA~1/R/R-2.7.1pat/library/Cairo/libs/Cai
 ro.dll':
   LoadLibrary failure:  The specified procedure could not be found.
 
 Error : .onLoad failed in 'loadNamespace' for 'Cairo'
 Error: package/namespace load failed for 'Cairo'
 
 with a dialog titled 'Rterm.exe - Entry Point Not Found' 
 saying 'The procedure entry point cairo_pdf_surface_create 
 could not be located in the dynamic link library libcairo-2.dll'.
 
 Loading the packages in the reverse order works, but the 
 Rterm seems unstable, e.g. calling q() immediately after will 
 exit the R session without questions:
 
 # Rterm --vanilla
  library(Cairo)
  library(EBImage)
  q()
 [Immediately back to the command line].
 
 I cannot reproduce the problem on R v2.7.1 on Ubuntu Hardy.
 
  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
 
 other attached packages:
 [1] EBImage_2.4.0 Cairo_1.4-2
 
 Cheers
 
 Henrik
 
 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel
 


**
The contents of this email are for the named addressee(s...{{dropped:22}}

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


Re: [Rd] Clash between 'Cairo' and 'EBImage' packages on Windows

2008-07-21 Thread Sklyar, Oleg (London)
Thanks fot the response. I will try to recompile EBImage with the newest
GTK and would advise Henrik to update the GTK to the latest one as it
should be backward compatible.

As for where it is posted, it is not a BioC only issue either and too
technical for R-help, so I would rather support Henrik on posting it
here. But please take my apollogies if it is not too appropriate to have
it on R-devel.

Best,
Oleg

Dr Oleg Sklyar
Technology Group
Man Investments Ltd
+44 (0)20 7144 3803
[EMAIL PROTECTED] 

 -Original Message-
 From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] 
 Sent: 21 July 2008 11:29
 To: Sklyar, Oleg (London)
 Cc: Henrik Bengtsson; R-devel
 Subject: Re: [Rd] Clash between 'Cairo' and 'EBImage' 
 packages on Windows
 
 On Mon, 21 Jul 2008, Sklyar, Oleg (London) wrote:
 
  EBImage is dynamically linked against GTK, which includes cairo 
  libraries, so those are installed along with GTK. Cairo seems to be 
  statically linking to libcairo.dll.a. I would assume that if it is
 
 That is an import library, so it is actually linked to 
 libcairo-2.dll, which it ships.
 
  linked statically it should not get confused with a shared library 
  present elsewhere in the path, but it looks like it does. I have no 
  solution for that because unlike Cairo I cannot not statically link 
  EBImage to GTK as it is not one library that I need, but a bunch of 
  those.
 
  On Linux you won't get this problem as it uses the same centrally 
  installed Cairo library.
 
  In a way it would be better, if Cairo relied on the 
 gladewin32.sf.net 
  which normally provides GTK (and thus cairo libraries) for 
 Windows and 
  linked dynamically, but probably to simplify user installations the 
  developers wanted to avoid this.
 
 It _is_ using dynamic loading, or there would be no conflict. 
  From the names, it looks very like that it is using a DLL 
 from gladewin32.
 
 The real issue looks rather like a versioning problem, that 
 the cairo libraries installed as part of GTK and used by 
 EBImage are way too old (cairo_pdf_surface_create was added 
 at cairo 1.2, and cairo is at 1.6.4). 
 So updating to the current GTK distribution may be all that 
 is needed (and Henrik could also try replacing your GTK's 
 libcairo-2.dll by that distributed with Cairo).
 
  There is not much I can do now about this, but I will follow the 
  thread if anybody comes up with an idea to change the code 
 if possible
 
 The Cairo package (which ships DLLs) could rename them, as R 
 itself does where it builds its own versions.  Or it could 
 link statically (if that works, which it does not for e.g. 
 package XML).
 
 I don't really understand why this was posted to R-devel: it 
 is not an R issue.
 
 
  Dr Oleg Sklyar
  Technology Group
  Man Investments Ltd
  +44 (0)20 7144 3803
  [EMAIL PROTECTED]
 
  -Original Message-
  From: [EMAIL PROTECTED]
  [mailto:[EMAIL PROTECTED] On Behalf Of Henrik 
 Bengtsson
  Sent: 19 July 2008 19:26
  To: R-devel
  Subject: [Rd] Clash between 'Cairo' and 'EBImage' packages 
 on Windows
 
  Hi,
 
  on Windows XP Pro with R version 2.7.1 Patched (2008-06-27
  r46012) the 'Cairo' and the 'EBImage' packages does not play
  well together.
 
  Loading EBImage before Cairo cause the following to happen:
 
  # Rterm --vanilla
  library(EBImage);
  library(Cairo)
  Error in inDL(x, as.logical(local), as.logical(now), ...) :
unable to load shared library
  'C:/PROGRA~1/R/R-2.7.1pat/library/Cairo/libs/Cai
  ro.dll':
LoadLibrary failure:  The specified procedure could not be found.
 
  Error : .onLoad failed in 'loadNamespace' for 'Cairo'
  Error: package/namespace load failed for 'Cairo'
 
  with a dialog titled 'Rterm.exe - Entry Point Not Found'
  saying 'The procedure entry point cairo_pdf_surface_create
  could not be located in the dynamic link library libcairo-2.dll'.
 
  Loading the packages in the reverse order works, but the
  Rterm seems unstable, e.g. calling q() immediately after will
  exit the R session without questions:
 
  # Rterm --vanilla
  library(Cairo)
  library(EBImage)
  q()
  [Immediately back to the command line].
 
  I cannot reproduce the problem on R v2.7.1 on Ubuntu Hardy.
 
  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
 
  other attached packages:
  [1] EBImage_2.4.0 Cairo_1.4-2
 
  Cheers
 
  Henrik
 
  __
  R-devel@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-devel
 
 
 
  
 **
  The contents of this email are for the named 
 addressee(s...{{dropped:22}}
 
  __
  R