[R] Pixmap problem

Roger Bivand Roger.Bivand at nhh.no
Wed Aug 25 21:42:55 CEST 2004


On Wed, 25 Aug 2004, Benjamin Lloyd-Hughes wrote:

> Hi,
> 
> I'm having trouble writing .pnm images which I think is due to a problem
> with my colour space.  The pixmap object seems to be looking for 72 of 8
> colours (one per cell?) which doesn't seem healthy...
> 
> > library(pixmap)
> > x <- pixmapIndexed(rep(1:8, 9), nrow=6, col=rainbow(8))
> > x
> Pixmap image
>   Type          : pixmapIndexed 
>   Size          : 6x12 
>   Resolution    : 1x1 
>   Bounding box  : 0 0 12 6 
>   Nr. of colors : 72 of 8 
> 
> > write.pnm(x, file="D:/Temp/output.pnm")
> Error in options(x) : evaluation nested too deeply: infinite recursion /
> options(expression=)?

This one is in:

> x <- pixmapIndexed(rep(1:8, 9), nrow=6, col=rainbow(8))
> as(x, "pixmapRGB")
Error in options(x) : evaluation nested too deeply: infinite recursion / 
options(expression=)?

and as(x, "pixmapRGB") is called to make the indexed pixmap 
an RGB pixmap, and hits:

setAs("pixmapIndexed", "pixmapRGB",
function(from, to){
    z = as(from, "pixmapRGB")

in setAs("pixmapIndexed", "pixmapRGB", ...

with traceback() saying, quite logically:

> traceback()
140: options(x)
139: getOption("topLevelEnvironment")
138: identical(envir, matchThisEnv)
137: topenv(parent.frame())
136: exists(classMetaName(Class), where)
135: isClass(class1)
134: possibleExtends(cl, class2)
133: is(fdef, "genericMethods")
132: getMethodsForDispatch(f, fdef)
131: getMethods("coerce")
130: .quickCoerceSelect(thisClass, Class)
129: as(from, "pixmapRGB")
128: asMethod(object)
...
5: as(from, "pixmapRGB")
4: asMethod(object)
3: as(from, "pixmapRGB")
2: asMethod(object)
1: as(x, "pixmap")

for me:

> version
         _                           
platform i686-pc-linux-gnu           
arch     i686                        
os       linux-gnu                   
system   i686, linux-gnu             
status   Under development (unstable)
major    2                           
minor    0.0                         
year     2004                        
month    08                          
day      06                          
language R                           

Until this is fixed, is it feasible for you to use pixmapRGB, not
pixmapIndexed, directly? "pixmapRGB" objects seem to pass through 
write.pnm() without trouble.

> >
> 
> Grey ones work but with a warning...
> 
> > x <- pixmapGrey(rep(1:8, 9), nrow=6)
> > x
> Pixmap image
>   Type          : pixmapGrey 
>   Size          : 6x12 
>   Resolution    : 1x1 
>   Bounding box  : 0 0 12 6 
> 
> > write.pnm(x, file="D:/Temp/output.pnm")
> Warning message: 
> connection is already open 
> >

> showConnections(TRUE)
  description class      mode text   isopen   can read can write
0 "stdin"     "terminal" "r"  "text" "opened" "yes"    "no"     
1 "stdout"    "terminal" "w"  "text" "opened" "no"     "yes"    
2 "stderr"    "terminal" "w"  "text" "opened" "no"     "yes"    

suggests that this is caused by a coding infelicity:

        con <- file(file, open="w")
        open(con, open="w")

in write.pnm() - the open() is unneeded, and will be removed in the next 
release.

> 
> Any ideas? 
> 
> Cheers, Ben
> [R 1.9.1 and Pixmap 0.4-1 under windows]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no




More information about the R-help mailing list