Re: [Rd] Task View for Marketing
On Sat, Dec 5, 2009 at 4:20 PM, Achim Zeileis wrote: > Charlotte: > >> I was wondering if a task view for marketing would be a good idea > > Maybe, do you want to volunteer to maintain it? > >> I realise that it would have some overlap with other task views. >> Social science, cluster and multivariate are the most obvious ones. > > Yes. I'm not sure how a new "Marketing" view would fit in the mix but maybe > you have some more precise ideas. > > If you would be willing to write such a view and maintain it in the future, > then I suggest that you put together a list of packages and some rough ideas > for text and how the marketing view would add to the views named above. Send > me the ideas (off-list) and then we can decide whether to go on or not. > > Thanks for the suggestion. > Best, > Z Achim I'm really honoured by the mere notion that I could ever maintain a CRAN task view. However honestly, I doubt that I have sufficient expertise for such a role. I will investigate the idea of a marketing view further, and if appropriate, get back to you. In the meantime, if others are interested...? kind regards -- Charlotte Maia http://sites.google.com/site/maiagx/home __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] raster support in graphics devices
I can confirm. Last time I checked (that is recently), there was no way to do it at the C level (beside possibly extreme hacks trying to work around what R does not want to expose, or go for patched source trees and builds). What is the status of this patch (accepted ? rejected ? else ?) This subject keeps appearing on the list, with the existence of a patch once contributed (3 years ago) acknowledged: http://www.mail-archive.com/r-h...@r-project.org/msg67172.html L. -- On Dec 5, 2009, at 4:11 PM, Romain Francois wrote: I agree too, I was just trying to put on the balance the amount of work that would require graphics supporting connections. Who's willing to do it ? The issue is not the will nor complexity on the GD side, but connections are not exposed outside of R (or at the C level), so there is currently no way to do it (AFAIR). Jeff Horner has proposed a patch long ago and Cairo works with connections if you patch R, but connections are to date still not part of the API. So I suspect the real issue is to create a connection API so packages (and devices) can use it. Cheers, Simon __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] raster support in graphics devices
On 12/06/2009 01:20 AM, Simon Urbanek wrote: On Dec 5, 2009, at 4:11 PM, Romain Francois wrote: I agree too, I was just trying to put on the balance the amount of work that would require graphics supporting connections. Who's willing to do it ? The issue is not the will nor complexity on the GD side, but connections are not exposed outside of R (or at the C level), so there is currently no way to do it (AFAIR). Jeff Horner has proposed a patch long ago and Cairo works with connections if you patch R, but connections are to date still not part of the API. So I suspect the real issue is to create a connection API so packages (and devices) can use it. Cheers, Simon As much as I'd love a C API for connections, streaming graphics out to connections don't necessarily have to depend on a C api. The trick we use in the RProtoBuf package to stream out to a binary connection is to call the R function writeBin several times. Something like: /* next element is some raw vector we want to stream out */ SEXP nextElement = PROTECT( getNextElement() ) ; /* con is the INTSXP connection number */ /* create the call : writeBin( nextElement, con ) */ SEXP call = PROTECT( lang3( "writeBin", nextElement, con ) ); SEXP res = PROTECT( eval( call, R_GlobalEnv) ) ; /* grab the number of bytes actually sent out */ int n = INTEGER(res)[0] ; UNPROTECT(3) ; /* res, call, nextElement */ We do the same with "readBin" to read from a binary connection chunk by chunk. Romain On 12/05/2009 07:06 PM, Tobias Verbeke wrote: Hi, Gabor Grothendieck wrote: Its not just the time. Its also the nuisance of having to manage files that I never needed in the first place. I agree with Gabor that it is more than a 'nice to have'. There are situations (when integrating R with other applications) you don't want to touch a disk and manage files afterwards (e.g. when one wants to pass a byte string). A recent question on the topic can be found here: http://tolstoy.newcastle.edu.au/R/e8/help/09/11/5902.html Best, Tobias On Fri, Dec 4, 2009 at 11:01 AM, Romain Francois wrote: On 12/04/2009 03:19 PM, Gabor Grothendieck wrote: Thanks. I am looking for the data to be just as if I had read in the png file (or wmf file or whatever). Hi, You are after the binary payload of the rendered graph as a png file. So you are going to have to go through a png file. It would be nice to be able to render to a binary connection, like a rawConnection, but it seems like an expensive "nice to have" grid.cap seems to give a bitmap and then would require some sort of processing to get the png or wmf, etc. form. Also note that I need it for classic graphics and not just grid graphics. grid.cap does not seem to care, baptiste code uses traditional graphics What I have right now works just as I want it _except_ I have to create a file and then read it back in which seems a waste. Can you measure the time it takes to do dev.off() and readBin ? On Fri, Dec 4, 2009 at 9:06 AM, baptiste auguie< baptiste.aug...@googlemail.com> wrote: Hi, You can use grid.cap, x11() plot(1:10) g = grid.cap() dev.off() str(g) # chr [1:672, 1:671] "white" "white" "white" "white" "white" ... but as far as I understand in ?grid.cap and the underlying code there is no "capGrob" equivalent that wouldn't require opening a new device before capturing the output. I hope I'm mistaken. Best, baptiste 2009/12/4 Gabor Grothendieck: Currently I have an application that saves the current graphics image (that was created with classic graphics or grid graphics) to a file and then reads the file back in using readBin: png("my.png") plot(1:10) dev.off() raw.img<- readBin("my.png", "raw", size = 1, n = 1) (I am doing this on Windows but would like to be able to do it on any platform.) Does the new raster functionality give me any way to get the object raw.img without creating the intermediate file, my.png? If so what is the corresponding code? On Mon, Nov 30, 2009 at 8:17 PM, Paul Murrell This is for developers of extension packages that provide extra *graphics devices* for R. In the *development* version of R, support has been added to the graphics engine for sending raster images (bitmaps) to a graphics device. This consists mainly of two new device functions: dev_Raster() and dev_Cap(). The R_GE_version constant (in GraphicsEngine.h) has been bumped up to 6 as a marker of this change. This means that, at a minimum, all graphics devices should be updated to provide dummy implementations of these new functions that just say the feature is not yet implemented (see for example the PicTeX and XFig devices in the 'grDevices' package). A full implementation of dev_Raster() should be able to draw a raster image (provided as an array of 32-bit R colors) at any size, possibly (bilinear) interpolated (otherwise nearest-neighbour), at any orientation, and with a per-pixel alpha channel. Where these are not natively su
Re: [Rd] raster support in graphics devices
On 12/06/2009 02:24 PM, Romain Francois wrote: On 12/06/2009 01:20 AM, Simon Urbanek wrote: On Dec 5, 2009, at 4:11 PM, Romain Francois wrote: I agree too, I was just trying to put on the balance the amount of work that would require graphics supporting connections. Who's willing to do it ? The issue is not the will nor complexity on the GD side, but connections are not exposed outside of R (or at the C level), so there is currently no way to do it (AFAIR). Jeff Horner has proposed a patch long ago and Cairo works with connections if you patch R, but connections are to date still not part of the API. So I suspect the real issue is to create a connection API so packages (and devices) can use it. Cheers, Simon As much as I'd love a C API for connections, streaming graphics out to connections don't necessarily have to depend on a C api. The trick we use in the RProtoBuf package to stream out to a binary connection is to call the R function writeBin several times. Something like: /* next element is some raw vector we want to stream out */ SEXP nextElement = PROTECT( getNextElement() ) ; /* con is the INTSXP connection number */ /* create the call : writeBin( nextElement, con ) */ SEXP call = PROTECT( lang3( "writeBin", nextElement, con ) ); I meant : lang3( install( "writeBin"), nextElement, con ) SEXP res = PROTECT( eval( call, R_GlobalEnv) ) ; /* grab the number of bytes actually sent out */ int n = INTEGER(res)[0] ; UNPROTECT(3) ; /* res, call, nextElement */ We do the same with "readBin" to read from a binary connection chunk by chunk. Romain On 12/05/2009 07:06 PM, Tobias Verbeke wrote: Hi, Gabor Grothendieck wrote: Its not just the time. Its also the nuisance of having to manage files that I never needed in the first place. I agree with Gabor that it is more than a 'nice to have'. There are situations (when integrating R with other applications) you don't want to touch a disk and manage files afterwards (e.g. when one wants to pass a byte string). A recent question on the topic can be found here: http://tolstoy.newcastle.edu.au/R/e8/help/09/11/5902.html Best, Tobias On Fri, Dec 4, 2009 at 11:01 AM, Romain Francois wrote: On 12/04/2009 03:19 PM, Gabor Grothendieck wrote: Thanks. I am looking for the data to be just as if I had read in the png file (or wmf file or whatever). Hi, You are after the binary payload of the rendered graph as a png file. So you are going to have to go through a png file. It would be nice to be able to render to a binary connection, like a rawConnection, but it seems like an expensive "nice to have" grid.cap seems to give a bitmap and then would require some sort of processing to get the png or wmf, etc. form. Also note that I need it for classic graphics and not just grid graphics. grid.cap does not seem to care, baptiste code uses traditional graphics What I have right now works just as I want it _except_ I have to create a file and then read it back in which seems a waste. Can you measure the time it takes to do dev.off() and readBin ? On Fri, Dec 4, 2009 at 9:06 AM, baptiste auguie< baptiste.aug...@googlemail.com> wrote: Hi, You can use grid.cap, x11() plot(1:10) g = grid.cap() dev.off() str(g) # chr [1:672, 1:671] "white" "white" "white" "white" "white" ... but as far as I understand in ?grid.cap and the underlying code there is no "capGrob" equivalent that wouldn't require opening a new device before capturing the output. I hope I'm mistaken. Best, baptiste 2009/12/4 Gabor Grothendieck: Currently I have an application that saves the current graphics image (that was created with classic graphics or grid graphics) to a file and then reads the file back in using readBin: png("my.png") plot(1:10) dev.off() raw.img<- readBin("my.png", "raw", size = 1, n = 1) (I am doing this on Windows but would like to be able to do it on any platform.) Does the new raster functionality give me any way to get the object raw.img without creating the intermediate file, my.png? If so what is the corresponding code? On Mon, Nov 30, 2009 at 8:17 PM, Paul Murrell This is for developers of extension packages that provide extra *graphics devices* for R. In the *development* version of R, support has been added to the graphics engine for sending raster images (bitmaps) to a graphics device. This consists mainly of two new device functions: dev_Raster() and dev_Cap(). The R_GE_version constant (in GraphicsEngine.h) has been bumped up to 6 as a marker of this change. This means that, at a minimum, all graphics devices should be updated to provide dummy implementations of these new functions that just say the feature is not yet implemented (see for example the PicTeX and XFig devices in the 'grDevices' package). A full implementation of dev_Raster() should be able to draw a raster image (provided as an array of 32-bit R colors) at any size, possibly (bilinear) interpolated (otherwise nearest-nei
Re: [Rd] raster support in graphics devices
On Dec 6, 2009, at 8:24 AM, Romain Francois wrote: > On 12/06/2009 01:20 AM, Simon Urbanek wrote: >> On Dec 5, 2009, at 4:11 PM, Romain Francois wrote: >> >>> I agree too, I was just trying to put on the balance the amount of work >>> that would require graphics supporting connections. >>> >>> Who's willing to do it ? >>> >> >> The issue is not the will nor complexity on the GD side, but connections are >> not exposed outside of R (or at the C level), so there is currently no way >> to do it (AFAIR). Jeff Horner has proposed a patch long ago and Cairo works >> with connections if you patch R, but connections are to date still not part >> of the API. So I suspect the real issue is to create a connection API so >> packages (and devices) can use it. >> >> Cheers, >> Simon > > As much as I'd love a C API for connections, streaming graphics out to > connections don't necessarily have to depend on a C api. The trick we use in > the RProtoBuf package to stream out to a binary connection is to call the R > function writeBin several times. Something like: > > /* next element is some raw vector we want to stream out */ > SEXP nextElement = PROTECT( getNextElement() ) ; > > /* con is the INTSXP connection number */ > /* create the call : writeBin( nextElement, con ) */ > SEXP call = PROTECT( lang3( "writeBin", nextElement, con ) ); > SEXP res = PROTECT( eval( call, R_GlobalEnv) ) ; > > /* grab the number of bytes actually sent out */ > int n = INTEGER(res)[0] ; > > UNPROTECT(3) ; /* res, call, nextElement */ > > We do the same with "readBin" to read from a binary connection chunk by chunk. > Well, that's a hack like any other and error handling will be a pain. Of course you can always use the evaluator, but I would not want to write or maintain a hack like that :) Cheers, Simon > > > >>> On 12/05/2009 07:06 PM, Tobias Verbeke wrote: Hi, Gabor Grothendieck wrote: > Its not just the time. Its also the nuisance of having to manage files > that > I never needed in the first place. I agree with Gabor that it is more than a 'nice to have'. There are situations (when integrating R with other applications) you don't want to touch a disk and manage files afterwards (e.g. when one wants to pass a byte string). A recent question on the topic can be found here: http://tolstoy.newcastle.edu.au/R/e8/help/09/11/5902.html Best, Tobias > On Fri, Dec 4, 2009 at 11:01 AM, Romain Francois > > wrote: > >> On 12/04/2009 03:19 PM, Gabor Grothendieck wrote: >> >>> Thanks. >>> >>> I am looking for the data to be just as if I had read in the png >>> file (or >>> wmf file or whatever). >>> >> Hi, >> >> You are after the binary payload of the rendered graph as a png file. So >> you are going to have to go through a png file. >> >> It would be nice to be able to render to a binary connection, like a >> rawConnection, but it seems like an expensive "nice to have" >> >> >> grid.cap seems to give a bitmap and then would >>> require some sort of processing to get the png or wmf, etc. form. Also >>> note >>> that I need it for classic graphics and not just grid graphics. >>> >> grid.cap does not seem to care, baptiste code uses traditional graphics >> >> >> What I have right now works just as I want it _except_ I have to >> create a >>> file and then read it back in which seems a waste. >>> >> Can you measure the time it takes to do dev.off() and readBin ? >> >> >> On Fri, Dec 4, 2009 at 9:06 AM, baptiste auguie< >>> baptiste.aug...@googlemail.com> wrote: >>> >>> Hi, You can use grid.cap, x11() plot(1:10) g = grid.cap() dev.off() str(g) # chr [1:672, 1:671] "white" "white" "white" "white" "white" ... but as far as I understand in ?grid.cap and the underlying code there is no "capGrob" equivalent that wouldn't require opening a new device before capturing the output. I hope I'm mistaken. Best, baptiste 2009/12/4 Gabor Grothendieck: > Currently I have an application that saves the current graphics image > (that > was created with classic graphics or grid graphics) to a file and > then > reads > the file back in using readBin: > > png("my.png") > plot(1:10) > dev.off() > raw.img<- readBin("my.png", "raw", size = 1, n = 1) > > (I am doing this on Windows but would like to be able to do it on any > platform.) > > Does the new raster functionality give me any way t
[Rd] PR#14099
The notes asked why an Ubuntu/Compiz problem is being reported on R-bugs. Answer: because the fact that no other application exhibits these redrawing problems seems to indicate that R is to blame, not Compiz. Furthermore, the data editor is not drawn properly with Metacity either (some row names missing until cursor is moved). Should I make a new bug report that does not mention Compiz? __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] raster support in graphics devices
On 12/06/2009 02:49 PM, Simon Urbanek wrote: On Dec 6, 2009, at 8:24 AM, Romain Francois wrote: On 12/06/2009 01:20 AM, Simon Urbanek wrote: On Dec 5, 2009, at 4:11 PM, Romain Francois wrote: I agree too, I was just trying to put on the balance the amount of work that would require graphics supporting connections. Who's willing to do it ? The issue is not the will nor complexity on the GD side, but connections are not exposed outside of R (or at the C level), so there is currently no way to do it (AFAIR). Jeff Horner has proposed a patch long ago and Cairo works with connections if you patch R, but connections are to date still not part of the API. So I suspect the real issue is to create a connection API so packages (and devices) can use it. Cheers, Simon As much as I'd love a C API for connections, streaming graphics out to connections don't necessarily have to depend on a C api. The trick we use in the RProtoBuf package to stream out to a binary connection is to call the R function writeBin several times. Something like: /* next element is some raw vector we want to stream out */ SEXP nextElement = PROTECT( getNextElement() ) ; /* con is the INTSXP connection number */ /* create the call : writeBin( nextElement, con ) */ SEXP call = PROTECT( lang3( "writeBin", nextElement, con ) ); SEXP res = PROTECT( eval( call, R_GlobalEnv) ) ; /* grab the number of bytes actually sent out */ int n = INTEGER(res)[0] ; UNPROTECT(3) ; /* res, call, nextElement */ We do the same with "readBin" to read from a binary connection chunk by chunk. Well, that's a hack like any other and error handling will be a pain. Of course you can always use the evaluator, but I would not want to write or maintain a hack like that :) Cheers, Simon Fair enough, so back to square one with Jeff's patch. Since jeff's original post or other reminders did not get replied (at least publicly), it is not clear what one can do to help moving to the direction of a C api for connection: a patch providing a higher level api, testing, documentation ? On 12/05/2009 07:06 PM, Tobias Verbeke wrote: Hi, Gabor Grothendieck wrote: Its not just the time. Its also the nuisance of having to manage files that I never needed in the first place. I agree with Gabor that it is more than a 'nice to have'. There are situations (when integrating R with other applications) you don't want to touch a disk and manage files afterwards (e.g. when one wants to pass a byte string). A recent question on the topic can be found here: http://tolstoy.newcastle.edu.au/R/e8/help/09/11/5902.html Best, Tobias On Fri, Dec 4, 2009 at 11:01 AM, Romain Francois wrote: On 12/04/2009 03:19 PM, Gabor Grothendieck wrote: Thanks. I am looking for the data to be just as if I had read in the png file (or wmf file or whatever). Hi, You are after the binary payload of the rendered graph as a png file. So you are going to have to go through a png file. It would be nice to be able to render to a binary connection, like a rawConnection, but it seems like an expensive "nice to have" grid.cap seems to give a bitmap and then would require some sort of processing to get the png or wmf, etc. form. Also note that I need it for classic graphics and not just grid graphics. grid.cap does not seem to care, baptiste code uses traditional graphics What I have right now works just as I want it _except_ I have to create a file and then read it back in which seems a waste. Can you measure the time it takes to do dev.off() and readBin ? On Fri, Dec 4, 2009 at 9:06 AM, baptiste auguie< baptiste.aug...@googlemail.com> wrote: Hi, You can use grid.cap, x11() plot(1:10) g = grid.cap() dev.off() str(g) # chr [1:672, 1:671] "white" "white" "white" "white" "white" ... but as far as I understand in ?grid.cap and the underlying code there is no "capGrob" equivalent that wouldn't require opening a new device before capturing the output. I hope I'm mistaken. Best, baptiste 2009/12/4 Gabor Grothendieck: Currently I have an application that saves the current graphics image (that was created with classic graphics or grid graphics) to a file and then reads the file back in using readBin: png("my.png") plot(1:10) dev.off() raw.img<- readBin("my.png", "raw", size = 1, n = 1) (I am doing this on Windows but would like to be able to do it on any platform.) Does the new raster functionality give me any way to get the object raw.img without creating the intermediate file, my.png? If so what is the corresponding code? On Mon, Nov 30, 2009 at 8:17 PM, Paul Murrell This is for developers of extension packages that provide extra *graphics devices* for R. In the *development* version of R, support has been added to the graphics engine for sending raster images (bitmaps) to a graphics device. This consists mainly of two new device functions: dev_Raster() and dev_Cap(). The R_GE_version constant (in GraphicsEngine.h) has b
Re: [Rd] PR#14099
ulrich.kel...@uni.lu wrote: The notes asked why an Ubuntu/Compiz problem is being reported on R-bugs. Answer: because the fact that no other application exhibits these redrawing problems seems to indicate that R is to blame, not Compiz. Wrong logic. And just because you have "the only" system that displays such behaviour does not imply that R is bug-free, nor that a workaround is necessarily impossible. Furthermore, the data editor is not drawn properly with Metacity either (some row names missing until cursor is moved). That's not true for Metacity on Fedora, it seems. Should I make a new bug report that does not mention Compiz? Certainly not! Hiding the fact that this is system-specific does not resolve the issue any faster. To the contrary, since it is system-specific, it is most likely to be analyzed and eventually fixed by someone with access to the specific system. However, R is an application that has worked across multiple X11 based platforms for many years. If R doesn't work on a new platform, I think it is fair to ask what is being done different on that platform, by filing a bug report for the system, if necessary. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] raster support in graphics devices
Hi baptiste auguie wrote: Hi again, I found two possible bugs related to grid.raster, one with the quartz device and the other with pdf. In my example I was playing with the idea of using grid.raster to create a filling pattern for rectangles. The pdf output does not seem to respect the clipping (it may have nothing to do with grid.raster though), whilst the quartz device with pdf file output often crashes for more than 4 different raster objects (but not always). I'm afraid I couldn't pinpoint the exact circumstance of the crash with a more concise example. Thanks again for the report. I have committed a fix for the PDF clipping. Still looking at the Quartz crashes. Paul Thanks in advance for any insights, baptiste ### Start example ### library(grid) ## create a motif grid45 <- function(..., width=0.5, height=0.5){ x11(width=width, height=height) grid.polygon(...) m <- grid.cap() dev.off() invisible(m) } .grid45 <- grid45() ## grid.raster(.grid45) tile.motif <- function(m, nx=10, ny=nx){ cols <- matrix(rep(m, nx), ncol=ncol(m)*nx, byrow=F) matrix(rep(t(cols), ny), nrow=nrow(cols)*ny, byrow=T) } ## quartz() ## grid.raster(tile.motif(.grid45, 2, 3)) patternGrob <- function(x=unit(0.5, "npc"), y=unit(0.5, "npc"), width=unit(1, "npc"), height=unit(1, "npc"), motif=matrix("white"), AR=1, motif.width=unit(5, "mm"), motif.height=AR*motif.width, pattern.offset=c(0, 0), # unimplemented default.units="npc", clip=TRUE, # testing purposes gp=gpar(fill=NA), ...) { grob(x=x, y=y, width=width, height=height, motif=motif, motif.width=motif.width, motif.height=motif.height, clip=clip, gp=gp, ..., cl="pattern") } widthDetails.pattern <- function(x) x$width heightDetails.pattern <- function(x) x$height drawDetails.pattern <- function(x, recording=TRUE){ ## calculate the number of tiles nx <- ceiling(convertUnit(x$width, "in", value=TRUE) / convertUnit(x$motif.width, "in", value=TRUE)) + 1 ny <- ceiling(convertUnit(x$height, "in", axisFrom = "y", value=TRUE) / convertUnit(x$motif.height, "in", axisFrom = "y", value=TRUE)) + 1 width <- convertUnit(x$width, "in") height <- convertUnit(x$height, "in", axisFrom = "y") ## clip the raster pushViewport(viewport(x=x$x, y=x$y, width=x$width, height=x$height, clip=x$clip)) grid.raster(tile.motif(x$motif, nx, ny), width=nx*x$motif.width, height=ny*x$motif.height) upViewport() ## overlay the rectangle grid.rect(x=x$x, y=x$y, width=x$width, height=x$height, just="center", gp=x$gp) } g <- patternGrob(x=0.7, width=unit(0.3, "npc"), height=unit(5.2, "cm"), clip=TRUE, motif=.grid45) ## interactive use: OK quartz() grid.newpage() grid.draw(g) ## png: OK png(file="pngClip.png") grid.newpage() grid.draw(g) dev.off() ## pdf: clipping does not occur pdf(file="pdfClip.pdf") grid.newpage() grid.draw(g) dev.off() ## quartz pdf: OK, but see below quartz(file="quartzClip.pdf", type="pdf") grid.newpage() grid.draw(g) dev.off() g1 <- patternGrob(x=0.2, width=unit(0.2, "npc"), height=unit(5.2, "cm"), clip=TRUE, motif=.grid45) g2 <- patternGrob(x=0.4, width=unit(0.2, "npc"), height=unit(5.2, "cm"), clip=TRUE, motif=.grid45) g3 <- patternGrob(x=0.6, width=unit(0.2, "npc"), height=unit(5.2, "cm"), clip=TRUE, motif=.grid45) g4 <- patternGrob(x=0.8, width=unit(0.2, "npc"), height=unit(5.2, "cm"), clip=TRUE, motif=.grid45) quartz(file="quartzClip2.pdf", type="pdf") grid.newpage() grid.draw(g1) grid.draw(g2) grid.draw(g3) grid.draw(g4) dev.off() *** caught segfault *** address 0x15dda018, cause 'memory not mapped' Traceback: 1: dev.off() sessionInfo() R version 2.11.0 Under development (unstable) (2009-11-30 r50622) i386-apple-darwin9.8.0 locale: [1] en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8 attached base packages: [1] grid stats graphics grDevices utils datasets methods [8] base 2009/12/2 Paul Murrell : Hi baptiste auguie wrote: Very nice, thank you for this great addition to R graphics! I can't wait to see lattice and ggplot2 functions that use rasterGrob to display images. The pdf output is so much better in every way! Incidentally, I ran into a segfault with grid.cap on the quartz device, but maybe it's normal at this stage. This may be due to the fact that I tested the changes on Mac OS X 10.6 (looks like you have 10.5 ?), plus the fact that I am feeling my way a bit on the Mac. I have access to a 10.4 machine so I will try to take a look there. Thanks for the report. Paul This works fine: library(grid) x1
Re: [Rd] raster support in graphics devices
Hi baptiste auguie wrote: Dear all, It seems to me that grid.raster is a special case of grid.rect as far as the intended visual output is concerned. The example below illustrates how both can be used to produce an image of the volcano data, I disagree. A "rect" grob is a vector object and a "raster" grob is a raster object and I think they should be kept distinct. You could possibly create a higher-level "image" object that is agnostic with respect to how it is implemented and have both "rect"-based and "raster"-based versions of that, but "rect" and "raster" are graphical primitives and at that level I think the distinction is useful. Paul d <- volcano cols <- grey(t(d)/max(c(d))) xy <- expand.grid(x=seq(0, 1, length=ncol(d)), y=seq(0, 1, length=nrow(d))) pdf("comparison.pdf", width=10, height=10/2*ncol(d)/nrow(d)) pushViewport(viewport(layout=grid.layout(1, 2))) pushViewport(viewport(layout.pos.r=1, layout.pos.c=1)) grid.rect(xy$y, rev(xy$x), 1/(nrow(d)), 1/(ncol(d)), gp=gpar(col=NA, fill=cols)) grid.text("grid.rect") upViewport() pushViewport(viewport(layout.pos.r=1, layout.pos.c=2)) cols.mat <- matrix(cols, ncol=ncol(d), byrow=T) grid.raster(t(cols.mat)) grid.text("grid.raster") dev.off() Of course grid.raster provides a much better output in terms of file size, speed, visualisation artifacts, and interpolation. My question though: is it necessary to have a distinct grob for raster output? Couldn't "raster" be an option in grid.rect when the width and height are constant? Alternatively, it might be useful to provide a function that converts a rectGrob into a rasterGrob, rect2raster <- function(g){ with(g, rasterGrob(matrix(gp$fill, ncol=length(unique(x))), mean(x),mean(y))) } This way, much of the existing code relying on grid.rect (e.g in lattice or ggplot2) could easily be adapted to work with grid.raster in favorable cases. Best regards, baptiste 2009/12/1 Paul Murrell : Hi This is for developers of extension packages that provide extra *graphics devices* for R. In the *development* version of R, support has been added to the graphics engine for sending raster images (bitmaps) to a graphics device. This consists mainly of two new device functions: dev_Raster() and dev_Cap(). The R_GE_version constant (in GraphicsEngine.h) has been bumped up to 6 as a marker of this change. This means that, at a minimum, all graphics devices should be updated to provide dummy implementations of these new functions that just say the feature is not yet implemented (see for example the PicTeX and XFig devices in the 'grDevices' package). A full implementation of dev_Raster() should be able to draw a raster image (provided as an array of 32-bit R colors) at any size, possibly (bilinear) interpolated (otherwise nearest-neighbour), at any orientation, and with a per-pixel alpha channel. Where these are not natively supported by a device, the graphics engine provides some routines for scaling and rotating raster images (see for example the X11 device). The dev_Cap() function should return a representation of a raster image captured from the current device. This will only make sense for some devices (see for example the Cairo device in the 'grDevices' package). A little more information and a couple of small examples are provided at http://developer.r-project.org/Raster/raster-RFC.html Paul -- 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 -- 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
Re: [Rd] raster support in graphics devices
Hi, 2009/12/6 Paul Murrell : > Hi > > > baptiste auguie wrote: >> >> Dear all, >> >> It seems to me that grid.raster is a special case of grid.rect as far >> as the intended visual output is concerned. The example below >> illustrates how both can be used to produce an image of the volcano >> data, > > > I disagree. A "rect" grob is a vector object and a "raster" grob is a > raster object and I think they should be kept distinct. You could possibly > create a higher-level "image" object that is agnostic with respect to how it > is implemented and have both "rect"-based and "raster"-based versions of > that, but "rect" and "raster" are graphical primitives and at that level I > think the distinction is useful. Fair point. I raised this question when trying to convert some ggplot2 code from grid.rect to grid.raster (for large images) and I came to the conclusions that a) it wasn't completely trivial (for me anyway); b) such conversion would probably be done over and over in the next few months by several different people. Your suggestion of a higher-level grob is interesting, and probably more elegant than a function that converts one grob to the other as I first envisaged. Thanks, baptiste > > Paul > > >> d <- volcano >> >> cols <- grey(t(d)/max(c(d))) >> xy <- expand.grid(x=seq(0, 1, length=ncol(d)), y=seq(0, 1, >> length=nrow(d))) >> >> pdf("comparison.pdf", width=10, height=10/2*ncol(d)/nrow(d)) >> pushViewport(viewport(layout=grid.layout(1, 2))) >> >> pushViewport(viewport(layout.pos.r=1, layout.pos.c=1)) >> grid.rect(xy$y, rev(xy$x), 1/(nrow(d)), 1/(ncol(d)), gp=gpar(col=NA, >> fill=cols)) >> grid.text("grid.rect") >> upViewport() >> >> pushViewport(viewport(layout.pos.r=1, layout.pos.c=2)) >> cols.mat <- matrix(cols, ncol=ncol(d), byrow=T) >> grid.raster(t(cols.mat)) >> grid.text("grid.raster") >> dev.off() >> >> Of course grid.raster provides a much better output in terms of file >> size, speed, visualisation artifacts, and interpolation. My question >> though: is it necessary to have a distinct grob for raster output? >> Couldn't "raster" be an option in grid.rect when the width and height >> are constant? >> >> Alternatively, it might be useful to provide a function that converts >> a rectGrob into a rasterGrob, >> >> rect2raster <- function(g){ >> >> with(g, >> rasterGrob(matrix(gp$fill, ncol=length(unique(x))), >> mean(x),mean(y))) >> } >> >> This way, much of the existing code relying on grid.rect (e.g in >> lattice or ggplot2) could easily be adapted to work with grid.raster >> in favorable cases. >> >> Best regards, >> >> baptiste >> >> >> >> 2009/12/1 Paul Murrell : >>> >>> Hi >>> >>> This is for developers of extension packages that provide extra *graphics >>> devices* for R. >>> >>> In the *development* version of R, support has been added to the graphics >>> engine for sending raster images (bitmaps) to a graphics device. This >>> consists mainly of two new device functions: dev_Raster() and dev_Cap(). >>> >>> The R_GE_version constant (in GraphicsEngine.h) has been bumped up to 6 >>> as a >>> marker of this change. >>> >>> This means that, at a minimum, all graphics devices should be updated to >>> provide dummy implementations of these new functions that just say the >>> feature is not yet implemented (see for example the PicTeX and XFig >>> devices >>> in the 'grDevices' package). >>> >>> A full implementation of dev_Raster() should be able to draw a raster >>> image >>> (provided as an array of 32-bit R colors) at any size, possibly >>> (bilinear) >>> interpolated (otherwise nearest-neighbour), at any orientation, and with >>> a >>> per-pixel alpha channel. Where these are not natively supported by a >>> device, the graphics engine provides some routines for scaling and >>> rotating >>> raster images (see for example the X11 device). The dev_Cap() function >>> should return a representation of a raster image captured from the >>> current >>> device. This will only make sense for some devices (see for example the >>> Cairo device in the 'grDevices' package). >>> >>> A little more information and a couple of small examples are provided at >>> http://developer.r-project.org/Raster/raster-RFC.html >>> >>> Paul >>> -- >>> 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 >>> > > -- > 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
Re: [Rd] raster support in graphics devices
Hi, Thanks for the fix. I hope the quartz bugs are not related to a bad configuration on my side (I don't have access to another Mac to test it). I was quite happy with this proof-of-concept of filling patterns for rectangles, and I was wondering if perhaps you had considered adding a similar tiling option to grid.raster (at the C level)? Best regards, baptiste 2009/12/6 Paul Murrell : > Hi > > > baptiste auguie wrote: >> >> Hi again, >> >> I found two possible bugs related to grid.raster, one with the quartz >> device and the other with pdf. >> >> In my example I was playing with the idea of using grid.raster to >> create a filling pattern for rectangles. The pdf output does not seem >> to respect the clipping (it may have nothing to do with grid.raster >> though), whilst the quartz device with pdf file output often crashes >> for more than 4 different raster objects (but not always). I'm afraid >> I couldn't pinpoint the exact circumstance of the crash with a more >> concise example. > > > Thanks again for the report. > > I have committed a fix for the PDF clipping. > > Still looking at the Quartz crashes. > > Paul > > >> Thanks in advance for any insights, >> >> baptiste >> >> ### Start example ### >> >> library(grid) >> >> ## create a motif >> grid45 <- function(..., width=0.5, height=0.5){ >> x11(width=width, height=height) >> grid.polygon(...) >> m <- grid.cap() >> dev.off() >> invisible(m) >> } >> >> .grid45 <- grid45() >> ## grid.raster(.grid45) >> >> tile.motif <- function(m, nx=10, ny=nx){ >> cols <- matrix(rep(m, nx), ncol=ncol(m)*nx, byrow=F) >> matrix(rep(t(cols), ny), nrow=nrow(cols)*ny, byrow=T) >> } >> >> ## quartz() >> ## grid.raster(tile.motif(.grid45, 2, 3)) >> >> patternGrob <- function(x=unit(0.5, "npc"), y=unit(0.5, "npc"), >> width=unit(1, "npc"), height=unit(1, "npc"), >> motif=matrix("white"), AR=1, >> motif.width=unit(5, "mm"), >> motif.height=AR*motif.width, >> pattern.offset=c(0, 0), # unimplemented >> default.units="npc", >> clip=TRUE, # testing purposes >> gp=gpar(fill=NA), ...) >> { >> grob(x=x, y=y, width=width, height=height, >> motif=motif, motif.width=motif.width, >> motif.height=motif.height, clip=clip, gp=gp, ..., cl="pattern") >> } >> >> widthDetails.pattern <- function(x) x$width >> heightDetails.pattern <- function(x) x$height >> >> drawDetails.pattern <- function(x, recording=TRUE){ >> >> ## calculate the number of tiles >> nx <- ceiling(convertUnit(x$width, "in", value=TRUE) / >> convertUnit(x$motif.width, "in", value=TRUE)) + 1 >> ny <- ceiling(convertUnit(x$height, "in", axisFrom = "y", value=TRUE) / >> convertUnit(x$motif.height, "in", axisFrom = "y", >> value=TRUE)) + 1 >> >> width <- convertUnit(x$width, "in") >> height <- convertUnit(x$height, "in", axisFrom = "y") >> >> ## clip the raster >> pushViewport(viewport(x=x$x, y=x$y, >> width=x$width, height=x$height, clip=x$clip)) >> >> grid.raster(tile.motif(x$motif, nx, ny), width=nx*x$motif.width, >> height=ny*x$motif.height) >> upViewport() >> >> ## overlay the rectangle >> grid.rect(x=x$x, y=x$y, >> width=x$width, height=x$height, >> just="center", gp=x$gp) >> } >> >> >> g <- patternGrob(x=0.7, width=unit(0.3, "npc"), >> height=unit(5.2, "cm"), >> clip=TRUE, motif=.grid45) >> >> ## interactive use: OK >> quartz() >> grid.newpage() >> grid.draw(g) >> >> ## png: OK >> png(file="pngClip.png") >> grid.newpage() >> grid.draw(g) >> dev.off() >> >> ## pdf: clipping does not occur >> pdf(file="pdfClip.pdf") >> grid.newpage() >> grid.draw(g) >> dev.off() >> >> ## quartz pdf: OK, but see below >> quartz(file="quartzClip.pdf", type="pdf") >> grid.newpage() >> grid.draw(g) >> dev.off() >> >> g1 <- patternGrob(x=0.2, width=unit(0.2, "npc"), >> height=unit(5.2, "cm"), >> clip=TRUE, motif=.grid45) >> >> g2 <- patternGrob(x=0.4, width=unit(0.2, "npc"), >> height=unit(5.2, "cm"), >> clip=TRUE, motif=.grid45) >> >> g3 <- patternGrob(x=0.6, width=unit(0.2, "npc"), >> height=unit(5.2, "cm"), >> clip=TRUE, motif=.grid45) >> >> g4 <- patternGrob(x=0.8, width=unit(0.2, "npc"), >> height=unit(5.2, "cm"), >> clip=TRUE, motif=.grid45) >> >> quartz(file="quartzClip2.pdf", type="pdf") >> grid.newpage() >> grid.draw(g1) >> grid.draw(g2) >> grid.draw(g3) >> grid.draw(g4) >> dev.off() >> >> *** caught segfault *** >> address 0x15dda018, cause 'memory not mapped' >> >> Traceback: >> 1: dev.off() >> >> sessionInfo() >> R version 2.11.0 Under development (unstable) (2009-11-30 r50622) >> i386-apple-darwin9.8.0 >> >> locale: >> [1] en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UT
[Rd] options(width=100) ignored on start-up: bug or feature?
Dear developers I've tried this a couple of days ago on r-help, unfortunately with no feedback. Could you please take a look and confirm whether it's a bug, feature, or bad eye-sight when reading Help: Is it normal that R ignores options("width"=100) at start-up? Although li...@debian-liv:~$ cat /usr/lib/R/etc/Rprofile.site | grep width options(width = 100) , R will start with [Previously saved workspace restored] > options()$width [1] 80 Am I doing something wrong? Liviu > sessionInfo() R version 2.10.0 (2009-10-26) x86_64-pc-linux-gnu locale: [1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_GB.UTF-8LC_COLLATE=en_GB.UTF-8 [5] LC_MONETARY=C LC_MESSAGES=en_GB.UTF-8 [7] LC_PAPER=en_GB.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] datasets grid splines graphics stats utils grDevices [8] tcltk methods base other attached packages: [1] fortunes_1.3-6 RcmdrPlugin.HH_1.1-25HH_2.1-32 [4] leaps_2.9multcomp_1.1-2 mvtnorm_0.9-8 [7] lattice_0.17-26 RcmdrPlugin.sos_0.1-0RcmdrPlugin.Export_0.3-0 [10] Hmisc_3.7-0 survival_2.35-7 xtable_1.5-6 [13] Rcmdr_1.5-4 car_1.2-16 relimp_1.0-1 [16] sos_1.1-7brew_1.0-3 hints_1.0.1-1 loaded via a namespace (and not attached): [1] cluster_1.12.1 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel