[Rd] extending lattice to S4 classes
Hi, I'm writing methods for a package called FLCore (see http://flr-project.org/) in particular for a class called "FLQuant" which extends array. Previously I was able to write methods based on the class of "data" but now I can not do it due to the single parameter "x". Is there a way to do this ? Regards EJ __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] extending lattice to S4 classes
ernesto wrote: >Hi, > >I'm writing methods for a package called FLCore (see >http://flr-project.org/) in particular for a class called "FLQuant" >which extends array. > >Previously I was able to write methods based on the class of "data" but >now I can not do it due to the single parameter "x". Is there a way to >do this ? > >Regards > >EJ > >__ >R-devel@r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-devel > > Hi, I found an hack (see below) to make it work but it's terrible and hugly ... some suggestions are welcome. It simply tests if data belongs to class "FLQuant" and transforms it into a data.frame before ploting. Regards EJ if (!isGeneric("xyplot")) { setGeneric("xyplot", useAsDefault = xyplot) } setMethod("xyplot", signature("formula"), function(x, ...){ dots <- list(...) if(class(dots$data)=="FLQuant") dots$data <- as.data.frame(dots$data) call.list <- c(x = x, dots) # needed this to avoid an infinite loop because xyplot is defined only for "x" xyplot <- lattice::xyplot ans <- do.call("xyplot", call.list) ans$call <- match.call() ans }) __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] extending lattice to S4 classes
Prof Brian Ripley wrote: > I think you are confusing us: xyplot is an S3 generic with no 'data' > argument. It is xyplot.formula that you want to add dispatch on its > 'data' argument. I don't really see why you want to mix S3 and S4 > systems, but you could make xyplot.formula an S3 or S4 generic and > dispatch on 'data', just as you did earlier with xyplot. > > Other xyplot methods need not (and probably do not) have a 'data' > argument. > > On Fri, 14 Oct 2005, ernesto wrote: > >> ernesto wrote: >> >>> Hi, >>> >>> I'm writing methods for a package called FLCore (see >>> http://flr-project.org/) in particular for a class called "FLQuant" >>> which extends array. >>> >>> Previously I was able to write methods based on the class of "data" but >>> now I can not do it due to the single parameter "x". Is there a way to >>> do this ? >> > >> I found an hack (see below) to make it work but it's terrible and hugly >> ... some suggestions are welcome. It simply tests if data belongs to >> class "FLQuant" and transforms it into a data.frame before ploting. >> >> Regards >> >> EJ >> >> if (!isGeneric("xyplot")) { >>setGeneric("xyplot", useAsDefault = xyplot) >> } >> >> >> setMethod("xyplot", signature("formula"), function(x, ...){ >> >>dots <- list(...) >>if(class(dots$data)=="FLQuant") dots$data <- as.data.frame(dots$data) >>call.list <- c(x = x, dots) >> >> # needed this to avoid an infinite loop because xyplot is defined only >> for "x" >>xyplot <- lattice::xyplot >>ans <- do.call("xyplot", call.list) >>ans$call <- match.call() >>ans >> >> }) > > Hi, Sorry to get back to this problem so late. I want to use lattice plots for an array. In this specific case this array is of class FLQuant which is defined by package FLCore. This array has 5 dimensions age, year, unit, season and area. My aim is to use formula to define what to plot and what to condition on. So procedures like used for barchart.table are not usefull for me because the user loses the option of defining the model to plot. With the previous version of lattice I was able to use formula and data to dispatch. So I defined S4 generic methods for most high level methods (bwplot, stripplot, dotplot, xyplot, histogram, etc) and simply transform FLQuant objects into dataframes that were passed to the lattice methods. No harm done to other data objects. With the new version only one object is available for dispatching "x" so if I define some xyplot.FLQuant I will miss the formula argument. My question is if there is a way of doing this or not. Best regards EJ __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] extending lattice to S4 classes
Deepayan Sarkar wrote: >On 10/18/05, ernesto <[EMAIL PROTECTED]> wrote: > > >>Prof Brian Ripley wrote: >> >> >> >>>I think you are confusing us: xyplot is an S3 generic with no 'data' >>>argument. It is xyplot.formula that you want to add dispatch on its >>>'data' argument. I don't really see why you want to mix S3 and S4 >>>systems, but you could make xyplot.formula an S3 or S4 generic and >>>dispatch on 'data', just as you did earlier with xyplot. >>> >>>Other xyplot methods need not (and probably do not) have a 'data' >>>argument. >>> >>>On Fri, 14 Oct 2005, ernesto wrote: >>> >>> >>> >>>>ernesto wrote: >>>> >>>> >>>> >>>>>Hi, >>>>> >>>>>I'm writing methods for a package called FLCore (see >>>>>http://flr-project.org/) in particular for a class called "FLQuant" >>>>>which extends array. >>>>> >>>>>Previously I was able to write methods based on the class of "data" but >>>>>now I can not do it due to the single parameter "x". Is there a way to >>>>>do this ? >>>>> >>>>> >>>>I found an hack (see below) to make it work but it's terrible and hugly >>>>... some suggestions are welcome. It simply tests if data belongs to >>>>class "FLQuant" and transforms it into a data.frame before ploting. >>>> >>>>Regards >>>> >>>>EJ >>>> >>>>if (!isGeneric("xyplot")) { >>>> setGeneric("xyplot", useAsDefault = xyplot) >>>>} >>>> >>>> >>>>setMethod("xyplot", signature("formula"), function(x, ...){ >>>> >>>> dots <- list(...) >>>> if(class(dots$data)=="FLQuant") dots$data <- as.data.frame(dots$data) >>>> call.list <- c(x = x, dots) >>>> >>>># needed this to avoid an infinite loop because xyplot is defined only >>>>for "x" >>>> xyplot <- lattice::xyplot >>>> ans <- do.call("xyplot", call.list) >>>> ans$call <- match.call() >>>> ans >>>> >>>>}) >>>> >>>> >>> >>> >>Hi, >> >>Sorry to get back to this problem so late. >> >>I want to use lattice plots for an array. In this specific case this >>array is of class FLQuant which is defined by package FLCore. >> >>This array has 5 dimensions age, year, unit, season and area. My aim is >>to use formula to define what to plot and what to condition on. So >>procedures like used for barchart.table are not usefull for me because >>the user loses the option of defining the model to plot. >> >>With the previous version of lattice I was able to use formula and data >>to dispatch. So I defined S4 generic methods for most high level methods >>(bwplot, stripplot, dotplot, xyplot, histogram, etc) and simply >>transform FLQuant objects into dataframes that were passed to the >>lattice methods. No harm done to other data objects. >> >>With the new version only one object is available for dispatching "x" so >>if I define some xyplot.FLQuant I will miss the formula argument. >> >>My question is if there is a way of doing this or not. >> >> > >Prof Ripley gave you one (redefine xyplot.formula etc). You could >always add new arguments to your methods, so you could have (the S4 >equivalent of) > >xyplot.FLQuant <- function(x, formula, ...) >{ >xyplot(formula, data = as(x, "data.frame"), ...) >} > >and then call > >xyplot(flq.obj, formula = y ~ x, [...]) > >The cleanest solution would be to have a data argument in the xyplot >generic (with the expectation that it could be non-missing only for >methods where x is a formula). I'll try to implement that and see if >it causes any problems. > >Deepayan > > Hi Deepayan, I see that there are alternatives, I found one my self that works and it's transparent for the user. I don't want to implement solutions that force the user to use lattice methods differently from your implementation. The cleanest solution as you say is to add a data argument to xyplot but I can't do it so I would not propose it. Regards EJ __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Overlaying lattice plots
Hillary, Richard M wrote: > Morning chaps, I have a little question for your capable minds... Say > I have an observed and predicted set of quants (in my case, length > frequencies by year and age/length), is there a way to use lattice > plots to plot the observed and predicted data together, panel by panel? > Obrigado/gracias (thankyou in Galego is?...) > Rich Hi Richard, If you want to plot both datasets on the same plot just make use of the xyplot for FLQuants, something like flqs <- FLQuants(list(pred=pred.quant, res=res.quant)) xyplot(data~age, data=flqs) now tune it the way you want and change the formula to fit your needs. Regards EJ ps: I'm cc'ing this to the mailing lists, I find it usefull for others. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Overlaying lattice plots - SORRY, WRONG MAILING LIST ADDRESS
ernesto wrote: >Hillary, Richard M wrote: > > > >>Morning chaps, I have a little question for your capable minds... Say >>I have an observed and predicted set of quants (in my case, length >>frequencies by year and age/length), is there a way to use lattice >>plots to plot the observed and predicted data together, panel by panel? >>Obrigado/gracias (thankyou in Galego is?...) >>Rich >> >> > >Hi Richard, > >If you want to plot both datasets on the same plot just make use of the >xyplot for FLQuants, something like > >flqs <- FLQuants(list(pred=pred.quant, res=res.quant)) >xyplot(data~age, data=flqs) > >now tune it the way you want and change the formula to fit your needs. > >Regards > >EJ > >ps: I'm cc'ing this to the mailing lists, I find it usefull for others. > > Hi, Sorry for this message, wrong address. I wanted to send it to FLR-mailing list. Regards EJ __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] extending lattice to S4 classes
Deepayan Sarkar wrote: >On 10/20/05, ernesto <[EMAIL PROTECTED]> wrote: > >[...] > > > >>Hi Deepayan, >> >>I see that there are alternatives, I found one my self that works and >>it's transparent for the user. >> >>I don't want to implement solutions that force the user to use lattice >>methods differently from your implementation. >> >>The cleanest solution as you say is to add a data argument to xyplot but >>I can't do it so I would not propose it. >> >> > >FYI, I have added the 'data' argument to high level generics in >lattice_0.13-1, available for r-devel (of course this causes the >current version of FLCore to fail). > >Deepayan >-- >http://www.stat.wisc.edu/~deepayan/ > > Hi, Thanks for your help. I'll deal with it asap. Regards EJ __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Cross compiling with R250
Hi, I'm cross compiling win R in a linux Ubuntu Edgy and I'm getting an error with the utils package. Sys.setenv exists on my R 2.5.0 ... I'm using the tools provided for R250 in http://www.stats.ox.ac.uk/pub/Rtools/i586-cross-tools.tar.bz2 Any ideas ? Regards EJ -- Making package utils adding build stamp to DESCRIPTION installing NAMESPACE file and metadata preparing package utils for lazy loading Error: could not find function "Sys.setenv" Execution halted make[5]: *** [lazyload] Error 1 make[4]: *** [all] Error 2 make[3]: *** [pkg-utils] Error 2 make[2]: *** [rpackage] Error 1 make[1]: *** [all] Error 2 make[1]: Leaving directory `/home/ernesto/ipimar/devel/R/ccompile250/WinR/R-2.5.0/src/gnuwin32' __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Cross compiling with R250
Hi, I wrongly assumed it would use R in the cross compiling directory and I did not found any reference to it on documentation. Obviously my fault, as you say. Regards EJ Prof Brian Ripley wrote: > You are pretty clearly not cross-compiling 'with R 2.5.0' (sic), as R > 2.5.0 does contain Sys.setenv. > > Looks like the R on Linux you are using is not R 2.5.0, and please > cross-check the instructions. > > This has been tested. > > On Mon, 30 Apr 2007, ernesto wrote: > >> Hi, >> >> I'm cross compiling win R in a linux Ubuntu Edgy and I'm getting an >> error with the utils package. Sys.setenv exists on my R 2.5.0 ... >> >> I'm using the tools provided for R250 in >> http://www.stats.ox.ac.uk/pub/Rtools/i586-cross-tools.tar.bz2 >> >> Any ideas ? >> >> Regards >> >> EJ >> >> >> -- Making package utils >> adding build stamp to DESCRIPTION >> installing NAMESPACE file and metadata >> preparing package utils for lazy loading >> Error: could not find function "Sys.setenv" >> Execution halted >> make[5]: *** [lazyload] Error 1 >> make[4]: *** [all] Error 2 >> make[3]: *** [pkg-utils] Error 2 >> make[2]: *** [rpackage] Error 1 >> make[1]: *** [all] Error 2 >> make[1]: Leaving directory >> `/home/ernesto/ipimar/devel/R/ccompile250/WinR/R-2.5.0/src/gnuwin32' >> >> __ >> 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] How to get the names of the classes exported by a specific package.
Hi, I'm writing some functions to generate Rd files for a S4 package. I want to have 2 character vectors with the names of the S4 classes and the methods exported by a package. To get the info about methods I'm using "getGenerics(where="package:FLCore")" however I can not find a similar process to get the S4 classes. Are there functions to access this information ? Best and thanks EJ __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] R260 cross-compilation
Hi, I'm trying to cross compile R260 in a ubuntu 6.06 linux. I downloaded the Makefile for 251 and simply replaced the R version by 260. However I'm getting an error about mingw. [EMAIL PROTECTED]:~/ipimar/devel/R/ccompile260$ make R export PATH=/home/ernesto/ipimar/devel/R/ccompile260/cross-tools/bin:/home/ernesto/ipimar/devel/R/ccompile260/cross-tools/i586-mingw32/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games; \ cd /home/ernesto/ipimar/devel/R/ccompile260/WinR/R-2.6.0/src/gnuwin32/; \ make; \ cd /home/ernesto/ipimar/devel/R/ccompile260/WinR; \ tar zcf Win-R-2.6.0.tgz R-2.6.0 make[1]: Entering directory `/home/ernesto/ipimar/devel/R/ccompile260/WinR/R-2.6.0/src/gnuwin32' make --no-print-directory -C front-ends Rpwd make -C ../../include -f Makefile.win version make Rpwd.exe i586-mingw32-gcc-sjlj -std=gnu99 -I../../include -O3 -Wall -pedantic -c rpwd.c -o rpwd.o make[4]: i586-mingw32-gcc-sjlj: Command not found make[4]: *** [rpwd.o] Error 127 make[3]: *** [Rpwd] Error 2 make[2]: *** [front-ends/Rpwd.exe] Error 2 make[1]: *** [all] Error 2 make[1]: Leaving directory `/home/ernesto/ipimar/devel/R/ccompile260/WinR/R-2.6.0/src/gnuwin32' How can I fix this ? Is there a new Makefile for R260 ? Thanks EJ __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] FLCore 4 R 2.3
Hi, I'm finding other problems with R 2.3 so let's release FLR 1.2 for R 2.2 and than see how to cope with R 2.3. Regards EJ __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] transform argument on 2.3 rc 2006-04-20
Hi, I'm adjusting package FLCore to the new R version and I got an error due to the change of the transform function argument "x" to "_data". Was this intentional ? Regards EJ __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] transform argument on 2.3 rc 2006-04-20
Kurt Hornik wrote: >>>>>>ernesto writes: >>>>>> >>>>>> > > > >>Hi, >> >> > > > >>I'm adjusting package FLCore to the new R version and I got an error >>due to the change of the transform function argument "x" to >>"_data". Was this intentional ? >> >> > >You mean that you get the error? :-) > >See NEWS: > >o The data frame argument to transform() is no longer called 'x', >but '_data'. Since this is an invalid name, it is less likely >to clash with names given to transformed variables. (People >were getting into trouble with transform(data, x=y+z).) > >See the code in base for how to use _data in code and docs. > >-k > > Ok, Thanks for your answer. I'll check the coding and docs. Regards EJ __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] histogram method for S4 class.
Deepayan Sarkar wrote: >On 8/24/05, ernesto <[EMAIL PROTECTED]> wrote: > > >>Hi, >> >>I'm trying to develop an histogram method for a class called "FLQuant" >>which is used by the package FLCore (http://flr-project.org). FLQuant is >>an extension to "array". There is an as.data.frame method that coerces >>flquant into a data.frame suitable for lattice plotting. The problem is >>that when I coerce the object and plot it after it works but if the >>method is applied within the histogram method it does not work. See the >>code below (the FLCore package is here >>http://prdownloads.sourceforge.net/flr/FLCore_1.0-1.tar.gz?download) >> >> >> >>>library(FLCore) >>> >>> >>Loading required package: lattice >> >> >>>data(ple4) >>>histogram(~data|year, [EMAIL PROTECTED]) >>> >>> >>Error in inherits(x, "factor") : Object "x" not found >> >> >>>histogram(~data|year, data=as.data.frame([EMAIL PROTECTED])) >>> >>> >>The catch.n slot is a FLQuant object and the code for histogram is the >>following >> >>setMethod("histogram", signature(formula="formula", data="FLQuant"), >>function (formula, data = parent.frame(), allow.multiple = >>is.null(groups) || outer, >>outer = FALSE, auto.key = FALSE, aspect = "fill", panel = >>"panel.histogram", prepanel = NULL, >>scales = list(), strip = TRUE, groups = NULL, xlab, xlim, ylab, >>ylim, >>type = c("percent", "count", "density"), >>nint = if (is.factor(x)) length(levels(x)) else >>round(log2(length(x)) + 1), >>endpoints = extend.limits(range(x[!is.na(x)]), prop = 0.04), >>breaks = if (is.factor(x)) seq(0.5, length = length(levels(x)) + >>1) else do.breaks(endpoints, nint), >>equal.widths = TRUE, drop.unused.levels = >>lattice.getOption("drop.unused.levels"), ..., >>default.scales = list(), subscripts = !is.null(groups), subset = >>TRUE) { >> >>qdf <- as.data.frame(data) >> >>histogram(formula, data = qdf, allow.multiple = allow.multiple, >>outer = outer, >>auto.key = auto.key, aspect = aspect, panel = panel, >>prepanel = prepanel, scales = scales, >>strip = strip, groups = groups, xlab=xlab, xlim=xlim, >>ylab=ylab, ylim=ylim, type = type, >>nint = nint, endpoints = endpoints, breaks = breaks, >>equal.widths = equal.widths, >>drop.unused.levels = drop.unused.levels, ..., default.scales >>= default.scales, >>subscripts = subscripts, subset = subset) >>} >>) >> >> >>Any ideas ? >> >> > >[I'm CC-ing to r-devel, please post follow-ups there] > >What version of lattice are you using? Please use the latest one, in >which histogram is an S3 generic, with only one argument, formula. The >eventual solution to your problem may involve changing that, but the >first question to ask is whether any other formula makes sense in your >context (if not, I would rather keep one argument and dispatch on >signature(formula = "FLQuant"). > >Disclaimer: I haven't actually had time to check out FLCore yet, I >will as soon as I can. > >Deepayan > > Hi, I've installed the version that is distributed with R-2.1.1, 0.11-8. I see there's a new version now so I'll install it and check the results. I've developed the code a little more using the approach you use for dotplot (see below) and I know where the problem is now. I'm not able to pass the argument nint, breaks and endpoints to the function call. I guess the problem is my programming skils :-( Thanks EJ ps: I'm not a subscriber of r-devel so I guess I'm not able to post there, anyway I'm CC-ing there too. setMethod("histogram", signature(formula="formula", data="FLQuant"), function (formula, data = parent.frame(), allow.multiple = is.null(groups) || outer, outer = FALSE, auto.key = FALSE, aspect = "fill", panel = "panel.histogram", prepanel = NULL, scales = list(), strip = TRUE, groups = NULL, xlab, xlim, ylab, ylim, type = c("percent", "count", "density"), nint = if (is.factor(x)) length(levels(x)) else round(log2(length(x)) + 1), endpoints = extend.limits(range(x[!is.na(x)]), prop = 0.04), breaks = if (is.factor(x)) seq(0.5, length = length(levels(x)) + 1) else do.