Re: [Rd] Dispatch method on S3 or S4 class

2010-09-07 Thread Martin Morgan
On 09/06/2010 10:00 PM, Dario Strbenac wrote:
> Hello,
>
> I've been attempting to make a generic method that dispatches on the first 
> argument, which can be either an S3 or an S4 class. This is as far as I've 
> gotten. Any suggestions about what to try next ?
>
> library(aroma.affymetrix)
> library(GenomicRanges)
>
> setGeneric("analyse", function(x, y, ...) standardGeneric("analyse"))
>
> setMethodS3("analyse", "AffymetrixCelSet", function(x, y, z, ...)
> {
>   x;
>   UseMethod("analyse")
> }
> )
>
> setGeneric("analyse")
>
> setMethod("analyse", "GRangesList", function(x, y, a, b, c)
> {
>   x;
> }
> )
I think (no testing on my end) you want

setOldClass("AffymetrixCelSet")

setGeneric("analyse", function(x, y, ...) standardGeneric("analyse"))

setMethod(analyse, "AffymetrixCelSet", function(x, y, z, ...)
{
cat("AffymetrixCelSet\n")
x
})

setMethod(analyse, "GRangesList", function(x, y, a, b, c)
{
cat("GRangesList\n")
x
})

and then by way of reproducible example

> x = analyse(structure(list(), class="AffymetrixCelSet"))
AffymetrixCelSet
> y = analyse(GRangesList())
GRangesList


Martin
>
> Thanks,
>Dario.
>
> --
> Dario Strbenac
> Research Assistant
> Cancer Epigenetics
> Garvan Institute of Medical Research
> Darlinghurst NSW 2010
> Australia
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

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


[Rd] as.character on NaN gives "NaN", is that intentional?

2010-09-07 Thread Ulrike Grömping

Dear DevelopeRs,

I am surprised about the outcome of the second command:

str(as.character(as.numeric("ee"))) 
str(as.character(log(-1)))


I would have expected a character NA. Is there an intention behind this 
behavior?


Best, Ulrike

--
*
* Ulrike Groemping  *
* BHT Berlin - University of Applied Sciences   *
*
* +49 (30) 39404863 (Home Office)   *
* +49 (30) 4504 5127 (BHT)  *
*
* http://prof.beuth-hochschule.de/groemping *
* groemp...@bht-berlin.de   *

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


Re: [Rd] as.character on NaN gives "NaN", is that intentional?

2010-09-07 Thread Kevin R. Coombes
 It seems to me that preserving information about the kind of number 
(or not) present would be useful. I rather like the fact that

   as.numeric(as.character(NaN))
and
   as.numeric(as.character(Inf))
both work as the identity operator on numeric-like objects.  (In this 
context, note that both is.numeric(NaN) and is.numeric(Inf) both return 
TRUE.)  In your example, the character string "ee" does not represent 
any number that I know about (at least in standard R).


Kevin

On 9/7/2010 11:23 AM, Ulrike Grömping wrote:

Dear DevelopeRs,

I am surprised about the outcome of the second command:

str(as.character(as.numeric("ee"))) str(as.character(log(-1)))

I would have expected a character NA. Is there an intention behind 
this behavior?


Best, Ulrike



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


[Rd] Is an R sub-session somehow possible?

2010-09-07 Thread ghostwheel

I wrote the interface between R and TeXmacs. Recently, I added tab
completion. However, there is one slight problem. In order to enable easy
interaction with R, I (I.e. my program) interact with the command-line
interface. This means that the user can invoke demo(), and then R will
interact with the user and ask to press enter.
It also means that the user can enter
a<-c(3,4
and then R will respond with '+'.

The problem is this: the way I implemented tab completion is calling an R
function that creates the completion. But, while in the middle of user
input, I can't call a function.

I guess that ESS for emacs has the same problem. when I enter "a<-c(3,4",
and then on the next line try to do tab completion, ESS replies that 'ESS
process is not ready. Finish your command before trying again'.
Of course while interacting with R on the command line, tab completion does
work.

So, the question is - is there any way to interrupt the current input to R,
call a function, get the return value, and then continue with the input
where it was? To do something similar to what pressing 'tab' in R does
internally? Something like the equivalent of ctrl-Z for a shell?

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Is-an-R-sub-session-somehow-possible-tp2530174p2530174.html
Sent from the R devel mailing list archive at Nabble.com.

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


[Rd] what is the best way for an external interface to interact with graphics, libraries

2010-09-07 Thread ghostwheel

Another message about the R to TeXmacs interface.

1. Graphics
The TeXmacs interface allows the user to directly insert graphics into the
session. 

Since I am not very familiar with programming for R, I implemented the
interaction with graphics in a very primitive way. It was two modes of
working: with X11, and without (for example when working remotely through
ssh without forwarding X11).

In both cases the user has to invoke a command, v(), in order to insert the
current graph into the buffer at the current place.

With X11, the way it works is that when v() is invoked I call recordPlot(),
then open a postscript file, then replayPlot(), and then close the
postscript file and insert it into the session.

Without X11, I open a postscript file ahead of time, then when v() is
called, I close it, and insert it into the session, and then open a new
postscript file.

Obviously quite primitive.I think ideally would be if everything was
transparent to the user - the user does a plot, and the plot is inserted
into the buffer right away, and later, updates to the same plot update the
original plot where it is. But to be able to do that I need to be able to
generate the postscript file of the current plot, and be notified somehow
whenever the plot changes.

Is all that possible? Is there a better way to implement this all?

2. Libraries

A remotely related question is this: the interface with TeXmacs generates
menus that depend on the currently loaded libraries. I'd like to be able to
update the menus whenever a new library is loaded. Is there a possibility to
have a function called whenever this happens? Or would it be advisable to
change the global 'library' function?

-- 
View this message in context: 
http://r.789695.n4.nabble.com/what-is-the-best-way-for-an-external-interface-to-interact-with-graphics-libraries-tp2530208p2530208.html
Sent from the R devel mailing list archive at Nabble.com.

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


Re: [Rd] Is an R sub-session somehow possible?

2010-09-07 Thread Simon Urbanek

On Sep 7, 2010, at 2:06 PM, ghostwheel wrote:

> 
> I wrote the interface between R and TeXmacs. Recently, I added tab
> completion. However, there is one slight problem. In order to enable easy
> interaction with R, I (I.e. my program) interact with the command-line
> interface. This means that the user can invoke demo(), and then R will
> interact with the user and ask to press enter.
> It also means that the user can enter
> a<-c(3,4
> and then R will respond with '+'.
> 
> The problem is this: the way I implemented tab completion is calling an R
> function that creates the completion. But, while in the middle of user
> input, I can't call a function.
> 

Why not? After the "+" prompt you're back in ReadConsole so it's safe.

Cheers,
Simon


> I guess that ESS for emacs has the same problem. when I enter "a<-c(3,4",
> and then on the next line try to do tab completion, ESS replies that 'ESS
> process is not ready. Finish your command before trying again'.
> Of course while interacting with R on the command line, tab completion does
> work.
> 
> So, the question is - is there any way to interrupt the current input to R,
> call a function, get the return value, and then continue with the input
> where it was? To do something similar to what pressing 'tab' in R does
> internally? Something like the equivalent of ctrl-Z for a shell?
> 
> -- 
> View this message in context: 
> http://r.789695.n4.nabble.com/Is-an-R-sub-session-somehow-possible-tp2530174p2530174.html
> Sent from the R devel mailing list archive at Nabble.com.
> 
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> 

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


Re: [Rd] what is the best way for an external interface to interact with graphics, libraries

2010-09-07 Thread Simon Urbanek

On Sep 7, 2010, at 2:21 PM, ghostwheel wrote:

> 
> Another message about the R to TeXmacs interface.
> 
> 1. Graphics
> The TeXmacs interface allows the user to directly insert graphics into the
> session. 
> 
> Since I am not very familiar with programming for R, I implemented the
> interaction with graphics in a very primitive way. It was two modes of
> working: with X11, and without (for example when working remotely through
> ssh without forwarding X11).
> 
> In both cases the user has to invoke a command, v(), in order to insert the
> current graph into the buffer at the current place.
> 
> With X11, the way it works is that when v() is invoked I call recordPlot(),
> then open a postscript file, then replayPlot(), and then close the
> postscript file and insert it into the session.
> 
> Without X11, I open a postscript file ahead of time, then when v() is
> called, I close it, and insert it into the session, and then open a new
> postscript file.
> 
> Obviously quite primitive.I think ideally would be if everything was
> transparent to the user - the user does a plot, and the plot is inserted
> into the buffer right away, and later, updates to the same plot update the
> original plot where it is. But to be able to do that I need to be able to
> generate the postscript file of the current plot, and be notified somehow
> whenever the plot changes.
> 
> Is all that possible? Is there a better way to implement this all?
> 

I don't know the mechanics of the actual "inserting" in TeXmac but it would be 
trivial to simply create a copy of the plot as EPS (or whatever is needed) at 
the time of insertion. See dev.copy2eps() for a function that does exactly that.



> 2. Libraries
> 
> A remotely related question is this: the interface with TeXmacs generates
> menus that depend on the currently loaded libraries.

Libraries are not "loaded" (see .libPath() for handling libraries) - but 
chances are that you meant packages...


> I'd like to be able to
> update the menus whenever a new library is loaded. Is there a possibility to
> have a function called whenever this happens? Or would it be advisable to
> change the global 'library' function?
> 

I would strongly advise against the latter. A reasonably simple way would be to 
check the search path - if it changed a package has been loaded. A natural 
place to do such check would be in a top-level task handler for example.

Cheers,
Simon

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


Re: [Rd] Is an R sub-session somehow possible?

2010-09-07 Thread ghostwheel


Simon Urbanek wrote:
> 
> 
> On Sep 7, 2010, at 2:06 PM, ghostwheel wrote:
> 
>> a<-c(3,4
>> and then R will respond with '+'.
>> 
>> The problem is this: the way I implemented tab completion is calling an R
>> function that creates the completion. But, while in the middle of user
>> input, I can't call a function.
>> 
> 
> Why not? After the "+" prompt you're back in ReadConsole so it's safe.
> 
> 

I see. ReadConsole() seems quite nice! I should use it.

What about remote sessions? Till now I used ssh, which then opened R. I
guess I could have the user compile and install the program that interfaces
with R on any machine that runs R. Is there another way?

Thanks,
Michael
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Is-an-R-sub-session-somehow-possible-tp2530174p2530233.html
Sent from the R devel mailing list archive at Nabble.com.

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


Re: [Rd] what is the best way for an external interface to interact with graphics, libraries

2010-09-07 Thread ghostwheel


Simon Urbanek wrote:
> 
> 
> I don't know the mechanics of the actual "inserting" in TeXmac but it
> would be trivial to simply create a copy of the plot as EPS (or whatever
> is needed) at the time of insertion. See dev.copy2eps() for a function
> that does exactly that.
> 
> 

Great. It works much better than my recordPlot() hack. But it seems to only
work for 'screen devices'. I'd like to be able to work remotely without X11.
Is there any equivalent graphics device that would be copyable with
dev.copy2eps?  Is there any way to tell R give me whatever you have till now
in eps? 


-- 
View this message in context: 
http://r.789695.n4.nabble.com/what-is-the-best-way-for-an-external-interface-to-interact-with-graphics-libraries-tp2530208p2530256.html
Sent from the R devel mailing list archive at Nabble.com.

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


Re: [Rd] as.character on NaN gives "NaN", is that intentional?

2010-09-07 Thread Ulrike Grömping

Kevin,

I wouldn't mind NaN (although it seems a bit strange, because you 
wouldn't expect a character to be a number), but I find it strange to 
get the character string "NaN". is.na(as.character(NaN)) returns FALSE, 
which is what I dislike.


Best, Ulrike

Kevin R. Coombes schrieb:
 It seems to me that preserving information about the kind of number 
(or not) present would be useful. I rather like the fact that

   as.numeric(as.character(NaN))
and
   as.numeric(as.character(Inf))
both work as the identity operator on numeric-like objects.  (In this 
context, note that both is.numeric(NaN) and is.numeric(Inf) both 
return TRUE.)  In your example, the character string "ee" does not 
represent any number that I know about (at least in standard R).


Kevin

On 9/7/2010 11:23 AM, Ulrike Grömping wrote:

Dear DevelopeRs,

I am surprised about the outcome of the second command:

str(as.character(as.numeric("ee"))) str(as.character(log(-1)))

I would have expected a character NA. Is there an intention behind 
this behavior?


Best, Ulrike



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


Re: [Rd] what is the best way for an external interface to interact with graphics, libraries

2010-09-07 Thread Simon Urbanek

On Sep 7, 2010, at 3:07 PM, ghostwheel wrote:

> 
> 
> Simon Urbanek wrote:
>> 
>> 
>> I don't know the mechanics of the actual "inserting" in TeXmac but it
>> would be trivial to simply create a copy of the plot as EPS (or whatever
>> is needed) at the time of insertion. See dev.copy2eps() for a function
>> that does exactly that.
>> 
>> 
> 
> Great. It works much better than my recordPlot() hack. But it seems to only
> work for 'screen devices'. I'd like to be able to work remotely without X11.
> Is there any equivalent graphics device that would be copyable with
> dev.copy2eps?  Is there any way to tell R give me whatever you have till now
> in eps? 
> 

No (AFAIR PS devoice does not keep a display list).

However, you can use any other device that uses a display list, e.g. CairoPS 
from the Cairo package (in fact any of the Cairo devices..).

Cheers,
Simon

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


Re: [Rd] Is an R sub-session somehow possible?

2010-09-07 Thread Simon Urbanek

On Sep 7, 2010, at 2:43 PM, ghostwheel wrote:

> 
> 
> Simon Urbanek wrote:
>> 
>> 
>> On Sep 7, 2010, at 2:06 PM, ghostwheel wrote:
>> 
>>> a<-c(3,4
>>> and then R will respond with '+'.
>>> 
>>> The problem is this: the way I implemented tab completion is calling an R
>>> function that creates the completion. But, while in the middle of user
>>> input, I can't call a function.
>>> 
>> 
>> Why not? After the "+" prompt you're back in ReadConsole so it's safe.
>> 
>> 
> 
> I see. ReadConsole() seems quite nice! I should use it.
> 
> What about remote sessions? Till now I used ssh, which then opened R. I
> guess I could have the user compile and install the program that interfaces
> with R on any machine that runs R. Is there another way?
> 

It doesn't really matter where the R is as long as you have some way of getting 
at the results. You are still leaving us in the dark as of what exactly you do 
(technically) so there is not much detail we can provide...

Cheers,
Simon

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


Re: [Rd] as.character on NaN gives "NaN", is that intentional?

2010-09-07 Thread Wolfgang Huber


Hi Ulrike

any set of three people will probably have five different opinions on 
this, but I can see that this makes sense:


NA - not available, not measured, not recorded
NaN - result of an arithmetic computation that lies outside of the real 
numbers; in that sense, "available".


However, this point of view then opens up the question why 'is.na(NaN)' 
is 'TRUE'.



Best wishes
Wolfgang

On 07/09/10 21:18, Ulrike Grömping wrote:

Kevin,

I wouldn't mind NaN (although it seems a bit strange, because you
wouldn't expect a character to be a number), but I find it strange to
get the character string "NaN". is.na(as.character(NaN)) returns FALSE,
which is what I dislike.

Best, Ulrike

Kevin R. Coombes schrieb:

It seems to me that preserving information about the kind of number
(or not) present would be useful. I rather like the fact that
as.numeric(as.character(NaN))
and
as.numeric(as.character(Inf))
both work as the identity operator on numeric-like objects. (In this
context, note that both is.numeric(NaN) and is.numeric(Inf) both
return TRUE.) In your example, the character string "ee" does not
represent any number that I know about (at least in standard R).

Kevin

On 9/7/2010 11:23 AM, Ulrike Grömping wrote:

Dear DevelopeRs,

I am surprised about the outcome of the second command:

str(as.character(as.numeric("ee"))) str(as.character(log(-1)))

I would have expected a character NA. Is there an intention behind
this behavior?

Best, Ulrike



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


--


Wolfgang Huber
EMBL
http://www.embl.de/research/units/genome_biology/huber

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


Re: [Rd] Is an R sub-session somehow possible?

2010-09-07 Thread ghostwheel


Simon Urbanek wrote:
> 
> 
> 
> It doesn't really matter where the R is as long as you have some way of
> getting at the results. You are still leaving us in the dark as of what
> exactly you do (technically) so there is not much detail we can provide...
> 
> 

Sorry, I'll try to provide more detail:

I am trying to provide a good connection between the TeXmacs editor and R.
(A really nice overview of such connections can be found in
http://www.r-project.org/conferences/useR-2004/abstracts/supplements/Urbanek.pdf
;)
What I do is fake a terminal, and interact with the command line interface
to R (something like what the program 'expect' does). To detect that R is
waiting for input I have to check various properties of the terminal. Not
really pretty.
What happens is that:
1. TeXmacs sends me a string to execute. 
2. I pass it to R, and wait for a prompt.
3. I pass all of R's return, somewhat processed back to TeXmacs. Thus, when 
I want to put a graphics inside TeXmacs' buffer, I have to print something
like 'start postscipt graphics', then the postscript file, then 'end
postscript'.

When the user asks for tab completion, TeXmacs sends me a special message
saying that this string needs to be completed. I call a function in R, and
return the result.

My program is able to interact with a remote R session, i.e. the session
will start on a different machine than the one TeXmacs runs on. Luckily, it
is also possible to detect when R waits for a prompt in a remote session by
doing these ugly terminal hacks.

In some cases the R prompt won't be a prompt for another command, but
instead, R is just waiting for user input, or for completion of the previous
input.

Now, my remaining question is this:
When I run R remotely, by emulating a terminal, and interacting with R in
command line mode, AND
when at the same time R is not waiting for a command, but instead for some
other kind of user interaction, my interface can't send to R a request to
execute the code to complete a certain string.
(I.e. call the function t.tab.complete that I attached below).

If I understand correctly, one solution is to write a replacement input
loop, so that R will call my ReadConsole() from time to time, and while I'm
inside that function, I could call R functions to provide tab completion.

In that case, for remote sessions, I would have to compile on the remote
computer this alternative R input loop, and I would have to have one for
every version of R that a user might want to run on the remote machine (the
machine I am currently working with remotely has 11 versions of R
installed...). I was wondering if there is still a way to avoid that, and
interact with the regular input loop, or maybe it is possible to load an
alternative input loop from a package/library inside an already running
regular R interface?
I would like the user to have to do as little as possible in terms of
installing additional programs on a remote machine.

Thanks,
I'm not sure if this was the type of additional information you meant...
Michael

Here is my tab completion routine, ("\2" and "\5" are the codes for TeXmacs
for a start and a stop of blocks. (basically like brackets) ).
-
t.tab.comp<-function(s,curs)
  {
rc.settings(help=F) #This is because of a bug in matchAvailableTopics in
package utils
rc.settings(file=T)

utils:::.assignLinebuffer(substr(s,1,curs))
utils:::.assignEnd(nchar(s))
utils:::.guessTokenFromLine()
utils:::.completeToken()
l=utils:::.retrieveCompletions()
l=sapply(l,function(x) {
  substr(x, nchar(utils:::.CompletionEnv[["token"]])+1,nchar(x) )
} )
i=grep("=$",l)
if( (length(l[-i]) > 10) & (length(i)>0 ) )
l=c(l[i])
s3=utils:::.CompletionEnv[["token"]]
s3=gsub("\"","\"",s3)
deb.l <<- l

cat("\2scheme:(tuple \"",s3,"\"",sep="") ;
cat(" \"")
if( length(l) > 0 )
{
  cat(l,sep="\" \"")
}
else
{
  #cat(s)
  cat("\"\"")
}
cat("\"")
cat(")\5")

   

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Is-an-R-sub-session-somehow-possible-tp2530174p2530527.html
Sent from the R devel mailing list archive at Nabble.com.

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


Re: [Rd] How to add a slot to S4 class of an existing package?

2010-09-07 Thread Sebastian P. Luque
Hi,

Is there a better approach to adding new slots to an S4 class without
breaking code that accesses older objects of that class than the
Bioconductor reference in the thread below?  Thanks.

Cheers,
Seb



On Mon, 29 Dec 2008 22:53:50 +,
Wolfgang Huber  wrote:

> Dear Christian this post from Martin Morgan on class versioning in
> Bioconductor's Biobase package might be relevant:
> https://stat.ethz.ch/pipermail/bioc-devel/2006-May/000545.html and
> also section 6 of this:
> http://www.bioconductor.org/packages/2.4/bioc/vignettes/Biobase/inst/doc/BiobaseDevelopment.pdf

>   Best wishes Wolfgang

>  Wolfgang Huber
> EMBL-EBI http://www.ebi.ac.uk/huber

> cstrato wrote:
>> Dear all,

>> Since my package is based on S4 classes, I would like to know how to
>> add a slot to an existing S4 class without breaking the code of users
>> of my package.

>> Assume the following S4 class: setClass("MyClass",
>> representation(name = "character", type = "character", data =
>> "data.frame" ), prototype(name = "", type = "Default", data =
>> data.frame(matrix(nr=0,nc=0)) ) )#MyClass

>> Assume that a user has created an object: > myclass <- new("MyClass",
>> name="MyName", type="MyType", data=tmp) > str(myclass)


>> Now I would like to add another slot "info" to MyClass:
>> setClass("MyClass", representation(name = "character", type =
>> "character", data = "data.frame", info = "data.frame" ),
>> prototype(name = "", type = "Default", data =
>> data.frame(matrix(nr=0,nc=0)), info = data.frame(matrix(nr=0,nc=0)) )
>> )#MyClass

>> Now when the user loads my package with S4 class MyClass containing a
>> new slot and calls: > str(myclass) Error in FUN(c("name", "type",
>> "data", "info")[[4L]], ...) : no slot of name "info" for this object
>> of class "MyClass"


>> My question is: Is there any possibility or special trick, which
>> would avoid this error message?

>> Are there other possibilities to access an additional data.frame from
>> an existing class?

>> Is there something like an "evolution" of S4 classes, which
>> distinguishes the different implementations of an S4 class, and
>> allows the user to keep the object of an old class?

>> Best regards Christian _._._._._._._._._._._._._._._._._._
>> C.h.r.i.s.t.i.a.n S.t.r.a.t.o.w.a V.i.e.n.n.a A.u.s.t.r.i.a
>> e.m.a.i.l: cstrato at aon.at _._._._._._._._._._._._._._._._._._

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


-- 
Seb

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


Re: [Rd] How to add a slot to S4 class of an existing package?

2010-09-07 Thread Kasper Daniel Hansen
Seb

That thread and the resources in Biobase assumes that you have a class
that extends "Versioned".  Doing so will help you in the long run by
providing you with updateObject (at the cost of some complexity).
However, it does not really help you if the existing class does not
extend Versioned.

In general, adding a new slot should not break any existing code, but
you may find users who have old objects lying around that they cannot
use with the new functionality (I assume you are adding slots to
provide new functionality).

Kasper

On Tue, Sep 7, 2010 at 7:39 PM, Sebastian P. Luque  wrote:
> Hi,
>
> Is there a better approach to adding new slots to an S4 class without
> breaking code that accesses older objects of that class than the
> Bioconductor reference in the thread below?  Thanks.
>
> Cheers,
> Seb
>
>
>
> On Mon, 29 Dec 2008 22:53:50 +,
> Wolfgang Huber  wrote:
>
>> Dear Christian this post from Martin Morgan on class versioning in
>> Bioconductor's Biobase package might be relevant:
>> https://stat.ethz.ch/pipermail/bioc-devel/2006-May/000545.html and
>> also section 6 of this:
>> http://www.bioconductor.org/packages/2.4/bioc/vignettes/Biobase/inst/doc/BiobaseDevelopment.pdf
>
>>       Best wishes Wolfgang
>
>>  Wolfgang Huber
>> EMBL-EBI http://www.ebi.ac.uk/huber
>
>> cstrato wrote:
>>> Dear all,
>
>>> Since my package is based on S4 classes, I would like to know how to
>>> add a slot to an existing S4 class without breaking the code of users
>>> of my package.
>
>>> Assume the following S4 class: setClass("MyClass",
>>> representation(name = "character", type = "character", data =
>>> "data.frame" ), prototype(name = "", type = "Default", data =
>>> data.frame(matrix(nr=0,nc=0)) ) )#MyClass
>
>>> Assume that a user has created an object: > myclass <- new("MyClass",
>>> name="MyName", type="MyType", data=tmp) > str(myclass)
>
>
>>> Now I would like to add another slot "info" to MyClass:
>>> setClass("MyClass", representation(name = "character", type =
>>> "character", data = "data.frame", info = "data.frame" ),
>>> prototype(name = "", type = "Default", data =
>>> data.frame(matrix(nr=0,nc=0)), info = data.frame(matrix(nr=0,nc=0)) )
>>> )#MyClass
>
>>> Now when the user loads my package with S4 class MyClass containing a
>>> new slot and calls: > str(myclass) Error in FUN(c("name", "type",
>>> "data", "info")[[4L]], ...) : no slot of name "info" for this object
>>> of class "MyClass"
>
>
>>> My question is: Is there any possibility or special trick, which
>>> would avoid this error message?
>
>>> Are there other possibilities to access an additional data.frame from
>>> an existing class?
>
>>> Is there something like an "evolution" of S4 classes, which
>>> distinguishes the different implementations of an S4 class, and
>>> allows the user to keep the object of an old class?
>
>>> Best regards Christian _._._._._._._._._._._._._._._._._._
>>> C.h.r.i.s.t.i.a.n S.t.r.a.t.o.w.a V.i.e.n.n.a A.u.s.t.r.i.a
>>> e.m.a.i.l: cstrato at aon.at _._._._._._._._._._._._._._._._._._
>
>>> __ R-devel@r-project.org
>>> mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
>
>
> --
> Seb
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

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


Re: [Rd] what is the best way for an external interface to interact with graphics, libraries

2010-09-07 Thread Paul Murrell

Hi

On 8/09/2010 9:23 a.m., Simon Urbanek wrote:


On Sep 7, 2010, at 3:07 PM, ghostwheel wrote:




Simon Urbanek wrote:



I don't know the mechanics of the actual "inserting" in TeXmac but it
would be trivial to simply create a copy of the plot as EPS (or whatever
is needed) at the time of insertion. See dev.copy2eps() for a function
that does exactly that.




Great. It works much better than my recordPlot() hack. But it seems to only
work for 'screen devices'. I'd like to be able to work remotely without X11.
Is there any equivalent graphics device that would be copyable with
dev.copy2eps?  Is there any way to tell R give me whatever you have till now
in eps?



No (AFAIR PS devoice does not keep a display list).


PS device does not keep a display list *by default*.  You should be able 
to turn it on via ...


dev.control("enable")

Paul


However, you can use any other device that uses a display list, e.g. CairoPS 
from the Cairo package (in fact any of the Cairo devices..).

Cheers,
Simon

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


--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
p...@stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/

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


[Rd] Correction to vec-subset speed patch

2010-09-07 Thread Radford Neal
I found a bug in one of the fourteen speed patches I posted, namely in
patch-vec-subset.  I've fixed this (I now see one does need to
duplicate index vectors sometimes, though one can avoid it most of the
time). I also split this patch in two, since it really has two
different and independent parts.  The patch-vec-subset patch now has
only some straightforward (locally-checkable) speedups for copies.
The new patch-subscript patch has the speedups for creation of index
vectors, which is where the bug was, and which generally have more
global interactions.  I made some other changes in the patch-subscript
part along with fixing the bug.

I've attached the new versions of the patches.  Here is the
documentation for the two revised patches:

patch-vec-subset

Speeds up extraction of subsets of vectors or matrices (eg, v[10:20]
or M[1:10,101:110]).  This is done with detailed code improvements.

Relevant test script:  test-vec-subset.r

There are lots of tests in this script.  The most dramatic improvement
is for extracting many rows and columns of a large array, where the 
improvement is by about a factor of four.  Extracting many rows from
one column of a matrix is sped up by about 30%. 

Changes unrelated to speed improvement:

Fixes two latent bugs where the code incorrectly refers to NA_LOGICAL
when NA_INTEGER is appropriate and where LOGICAL and INTEGER types
are treated as interchangeable.  These cause no problems at the moment,
but would if representations were changed.

patch-subscript

(Formerly part of patch-vec-subset)  This patch also speeds up
extraction, and also replacement, of subsets of vectors or
matrices, but focuses on the creation of the indexes rather than
the copy operations.  Often avoids a duplication (see below) and
eliminates a second scan of the subscript vector for zero
subscripts, folding it into a previous scan at no additional cost.

Relevant test script:  test-vec-subset.r

Speeds up some operations with scalar or short vector indexes by
about 10%.  Speeds up subscripting with a longer vector of
positive indexes by about 20%.

Issues:  The current code duplicates a vector of indexes when it
seems unnecessary.  Duplication is for two reasons:  to handle
the situation where the index vector is itself being modified in
a replace operation, and so that any attributes can be removed, which 
is helpful only for string subscripts, given how the routine to handle 
them returns information via an attribute.  Duplication for the
second reasons can easily be avoided, so I avoided it.  The first
reason for duplication is sometimes valid, but can usually be avoided
by first only doing it if the subscript is to be used for replacement
rather than extraction, and second only doing it if the NAMED field
for the subscript isn't zero.

I also removed two layers of procedure call overhead (passing seven
arguments, so not trivial) that seemed to be doing nothing.  Probably 
it used to do something, but no longer does, but if instead it is 
preparation for some future use, then removing it might be a mistake.
Index: src/main/subset.c
===
--- src/main/subset.c   (revision 52822)
+++ src/main/subset.c   (working copy)
@@ -59,73 +59,77 @@
 if (x == R_NilValue)
return x;
 
-for (i = 0; i < n; i++) {
-   ii = INTEGER(indx)[i];
-   if (ii != NA_INTEGER)
-   ii--;
-   switch (mode) {
-   case LGLSXP:
-   if (0 <= ii && ii < nx && ii != NA_LOGICAL)
-   LOGICAL(result)[i] = LOGICAL(x)[ii];
-   else
-   LOGICAL(result)[i] = NA_INTEGER;
-   break;
-   case INTSXP:
-   if (0 <= ii && ii < nx && ii != NA_INTEGER)
-   INTEGER(result)[i] = INTEGER(x)[ii];
-   else
-   INTEGER(result)[i] = NA_INTEGER;
-   break;
-   case REALSXP:
-   if (0 <= ii && ii < nx && ii != NA_INTEGER)
-   REAL(result)[i] = REAL(x)[ii];
-   else
-   REAL(result)[i] = NA_REAL;
-   break;
-   case CPLXSXP:
-   if (0 <= ii && ii < nx && ii != NA_INTEGER) {
-   COMPLEX(result)[i] = COMPLEX(x)[ii];
-   }
-   else {
-   COMPLEX(result)[i].r = NA_REAL;
-   COMPLEX(result)[i].i = NA_REAL;
-   }
-   break;
-   case STRSXP:
-   if (0 <= ii && ii < nx && ii != NA_INTEGER)
-   SET_STRING_ELT(result, i, STRING_ELT(x, ii));
-   else
-   SET_STRING_ELT(result, i, NA_STRING);
-   break;
-   case VECSXP:
-   case EXPRSXP:
-   if (0 <= ii && ii < nx && ii != NA_INTEGER)
-   SET_VECTOR_ELT(result, i, VECTOR_ELT(x, ii));
-   else
-   SET_VECTOR_ELT(result, i, R_NilValue);
-   br