how to enable plotting in R

1793 views
Skip to first unread message

emil

unread,
Dec 29, 2010, 4:25:11 AM12/29/10
to sage-support
I have a question regarding plotting in R.
If I go to Notebook (change to r from the drop down menu) and type

x<-c(1,2,3)
plot(x)

I get a strange error message:
Error in png(): X11 is not available

I have made the start scripts available with
install_scripts('/usr/bin'). If I issue those commands in the R
console then nothing happens (without error message).

if I issue capabilities() I get the following results:

jpeg (FALSE ) png (FALSE) tiff (FALSE ) tcltk (FALSE) X11
(FALSE) aqua (FALSE) http/ftp (TRUE ) sockets (TRUE ) libxml
(TRUE ) fifo (TRUE) cledit (TRUE ) iconv (TRUE) NLS (TRUE)
profmem (FALSE ) cairo (FALSE)

So R thinks I have no X11 system ( I have, xorg with JWM and GTK) and
no support for graphic files (I have libpng.so installed in /usr/lib ,
and I also find it in the sage tree, so probably sage has its own
version)

I had googled alot and found there were some issues with the R-
plotting interface, but as far as I understood this should be fixed,
so basically it should be possible to plot from R.

This is in the live CD version which uses Puppy Linux (has Ubuntu
Binaries). I installed sage (4.6) directly from the Ubuntu binaries
(passed sage -testall without errors). Could this be fixed easily
(maybe some symlinks?). Or is there a chance for a fix if I compile
sage on the system from source?

I also tried the current vmimage on a windows host and it gives the
same for r.capabilities().

I got feedback from people who are very interested in the sage package
but mainly want to use some components in a "classical" way (e.g.
Rcmdr with R) - Do you think this is possible at all?

many thanks for any hint on this
emil



Harald Schilly

unread,
Dec 29, 2010, 7:28:26 AM12/29/10
to sage-s...@googlegroups.com


On Wednesday, December 29, 2010 10:25:11 AM UTC+1, emil wrote:

I got feedback from people who are very interested in the sage package
but mainly want to use some components in a "classical" way (e.g.
Rcmdr with R) - Do you think this is possible at all?


Just about that, yes, you can use Sage just as a distribution of scientific software. On the commanline, just enter $ sage -sh and you are inside the so called sage environment. There, you can start any of it's programs, and in your case, you can start R and install the R commander. Via this environment you basically bypass everything of sage and you have direct control of all tools. (i.e. theoretically, you could download and install a binary version of R from their website while being in that environment, replacing the one from sage)
Unfortunately, I tried it and I got errors installing the Rcmdr package .. 

H

emil

unread,
Dec 29, 2010, 10:07:36 AM12/29/10
to sage-support
Hello Harald,

yes, It is not working as expected. Expected behaviour would be that
you have access to the R plotting engine and (after installing the
Developer package with gcc etc) you can install packages (including
Rcmdr).

Some days ago I wanted build Texmacs, I compiled it from source and
got it working, but plotting was broken too - so I dumped it because I
though there is something wrong with my Texmacs build, but maybe this
problem has the same roots.

I just want to mention that of the feedback from the last sage live CD
at least half of all users who try it are interested mainly in one
component (R, Python with libraries, maxima).

So I really would like to fix this and have a working direct access
from outside sage to those packages. What would be the best approach?
Should there be a "track ticket" or later even something in the
doctests to test this functionality? Sorry I am clueless here, its a
bit above my head.

kind regards
emil





kcrisman

unread,
Dec 29, 2010, 12:33:18 PM12/29/10
to sage-support
The main problem is that Puppy Linux or whatever must have compiled
Sage without the right headers available. It's entirely mysterious to
us exactly why R requires certain developer tools installed to give
you X11. But it doesn't, and so in the spkg-install we check for as
many of these things as we know about. However, the Puppy
installation probably doesn't have them all, so when it compiled R, it
did so without support for this. Here is part of it (without some
comments):

if [ -f /usr/include/X11/Xwindows.h ]; then
XSUPPORT=yes
else
if [ "x`uname`" = xSunOS ] && [ -f /usr/X11/lib/libXv.so ] ; then
XSUPPORT=yes
else
XSUPPORT=no
fi
fi

On Mac we instead enable Aqua, because X11 support is very difficult
to implement for the general case (it depends heavily on version of OS
X).

So one solution would be to compile Sage from scratch (which is easy);
another is to download a binary built on a machine which had these
things. We really wish there was a good solution to this, but
repeated requests on the R help list did not lead to further
elucidation.

Also, not all R packages behave nicely in this way - I've had trouble
installing ones that assumed access to certain things like OpenGL as
well. But you are right that big ones like R Commander should be ok.

I'm not sure whether this will help, but it should help understand
what the problem is, anyway.

- kcrisman

emil

unread,
Dec 29, 2010, 1:49:00 PM12/29/10
to sage-support
Ok, thanks for the pointers!

In fact, as I said, I have just used the usual ubuntu binaries from
the sage server to make
the live cd. I did this because I figured this could be a possibility
to reduce the amount of work to have a working
live CD considerably (given the fast release cycle of sage). And, as I
said, it passed sage -testall without errors (exception: cython throws
on error because there is no gcc installed in the base distribution).
Also, as mentioned, the current ubuntu vmware image has exactly the
same problem (i.e. plotting in R doesn't work, r.capabilities() give
the same values).

Also I have every header installed in my installation. There is a well
tested development package, and I have even installed all the kernel
headers . So I doubt it is really a problem of missing header files in
the base OS. The same packages are used for all compiling purposes.

I will compile a version of R and try to get it working, then I will
compile sage from scratch an use it instead of the ubuntu binaries.
Lets see where "the dog is burried" (german proverb).

So is it right to say that plotting from R, and installation of most R-
packages should work in a working sage install?
Just to be sure it's no ghost I'm hunting ...
emil

emil

unread,
Jan 2, 2011, 12:05:59 PM1/2/11
to sage-support
So R-graphics in sage don't work by default, this is probably exactly
http://trac.sagemath.org/sage_trac/ticket/8868

It is not working in the Ubuntu 32 bit binaries, the ubuntu 64 bit
binaries and the current VM image.

I built R from source on my machine, and I have

jpeg (TRUE ) png (TRUEE) tiff (TRUE ) tcltk (TRUE) X11
(TRUE) aqua (FALSE) http/ftp (TRUE ) sockets (TRUE ) libxml
(TRUE ) fifo (TRUE) cledit (TRUE ) iconv (TRUE) NLS (TRUE)
profmem (FALSE ) cairo (TRUE)

- i.e. all but aqua and profmem are TRUE

So if I want to recompile sage from source (with FAT_BINARIES=TRUE),
what compile options do I need to get those things working? Or could
anyone point me to the right place inside the sage install scripts?

I also think that there should be an error or at least a warning about
failing R plotting when doing
sage -testall.

Happy new year to all,
emil


emil

unread,
Jan 4, 2011, 12:19:33 PM1/4/11
to sage-support

> > > The main problem is that Puppy Linux or whatever must have compiled
> > > Sage without the right headers available.  It's entirely mysterious to
> > > us exactly why R requires certain developer tools installed to give
> > > you X11.  But it doesn't, and so in the spkg-install we check for as
> > > many of these things as we know about.  However, the Puppy
> > > installation probably doesn't have them all, so when it compiled R, it
> > > did so without support for this.   Here is part of it (without some
> > > comments):
>
> > > if [ -f /usr/include/X11/Xwindows.h ]; then
> > >     XSUPPORT=yes
> > > else
> > >    if [ "x`uname`" = xSunOS ] && [ -f /usr/X11/lib/libXv.so ] ; then
> > >        XSUPPORT=yes
> > >    else
> > >        XSUPPORT=no
> > >    fi
> > > fi
>
> > > So one solution would be to compile Sage from scratch (which is easy);
> > > another is to download a binary built on a machine which had these
> > > things.  We really wish there was a good solution to this, but
> > > repeated requests on the R help list did not lead to further
> > > elucidation.
>

> > > I'm not sure whether this will help, but it should help understand
> > > what the problem is, anyway.

OK,
i compiled sage from scratch without any special options and plotting
works
r.capabilities() gives the same results as the separate R build.
That solves the problem for now - thanks.

What I can't understand is why this is not working in the precompiled
ubuntu binaries and VM image (without warning). It would have been
convenient to use those binaries, but it is no problem to compile sage
for every version from scratch.





kcrisman

unread,
Jan 4, 2011, 1:05:40 PM1/4/11
to sage-support
> OK,
> i compiled sage from scratch without any  special options and plotting
> works
> r.capabilities() gives the same results as the separate R build.
> That solves the problem for now - thanks.

Great!

>
> What I can't understand is why this is not working in the precompiled
> ubuntu binaries and VM image (without warning). It would have been

The tests for that are optional - we can't assume every system with
Sage has the right stuff, unfortunately. Why the VM image *and*
Ubuntu binaries don't have it is a mystery; my guess is that they are
compiled on some virtual machine on some other machine, and that the
virtual machine is a minimal setup. I don't know where those binaries
are created, though.

- kcrisman

emil

unread,
Jan 5, 2011, 9:15:07 AM1/5/11
to sage-support

>
> The tests for that are optional - we can't assume every system with
> Sage has the right stuff, unfortunately.  Why the VM image *and*
> Ubuntu binaries don't have it is a mystery; my guess is that they are
> compiled on some virtual machine on some other machine, and that the
> virtual machine is a minimal setup.  I don't know where those binaries
> are created, though.
>
> - kcrisman

I understand the reasoning and that it is impossible to have every
feature working out of the box on every machine. In case of plotting
in R I think this is one of the finest parts of that package, so its a
shame it is problematic.

I was always ignorant of sage -testall --optional! ;-) I always
thought I am very thouroughgoing with my sage -testall after each
installation.

Hm, does R need the Xorg - dev headers to work properly? Thats the
only reason I can imagine it is not feasable to build that into a
standard binary (X and linpng should be there in 99.99 % of Ubuntu
installs). I am not sure about it, because I have tested an R package
without those headers installed, and demo(graphics) worked fine. The
VM is a different story, but it should be possible to build one where
plotting is working.

emil

kcrisman

unread,
Jan 5, 2011, 1:23:01 PM1/5/11
to sage-support


On Jan 5, 9:15 am, emil <emil.widm...@gmail.com> wrote:
> > The tests for that are optional - we can't assume every system with
> > Sage has the right stuff, unfortunately.  Why the VM image *and*
> > Ubuntu binaries don't have it is a mystery; my guess is that they are
> > compiled on some virtual machine on some other machine, and that the
> > virtual machine is a minimal setup.  I don't know where those binaries
> > are created, though.
>
> > - kcrisman
>
> I understand the reasoning and that it is impossible to have every
> feature working out of the box on every machine. In case of plotting
> in R I think this is one of the finest parts of that package, so its a
> shame it is problematic.
>
> I was always ignorant of sage -testall --optional! ;-) I always
> thought I am very thouroughgoing with my sage -testall after each
> installation.
>
> Hm, does R need the Xorg - dev headers to work properly? Thats the

Well, I don't know why, but they apparently think so. It's in the
documentation that this (or something like it) should be in to build
these things. I really need to ask their devel list someday...

- kcrisman

emil

unread,
Jan 6, 2011, 3:45:01 AM1/6/11
to sage-support

>
> > Hm, does R need the Xorg - dev headers to work properly? Thats the
>
> Well, I don't know why, but they apparently think so.  It's in the
> documentation that this (or something like it) should be in to build
> these things.  I really need to ask their devel list someday...
>
> - kcrisman
>

Maybe it is so, that those headers are necessary to build, but not
necessary to run ...
In that case it makes sense that this feature is optional when
building. But nevertheless
binaries should be built with them, because people can run it without
Xorg headers.

emil

unread,
Jan 6, 2011, 4:37:27 AM1/6/11
to sage-support

>Just about that, yes, you can use Sage just as a distribution of scientific
>software. On the commanline, just enter $ sage -sh and you are inside the so
>called sage environment. There, you can start any of it's programs, and in
>your case, you can start R and install the R commander. Via this environment
>you basically bypass everything of sage and you have direct control of all
>tools. (i.e. theoretically, you could download and install a binary version
>of R from their website while being in that environment, replacing the one
>from sage)
>Unfortunately, I tried it and I got errors installing the Rcmdr package ..

>H

For sake of completeness I have to add that I just did

sage -sh
R
install.packages("Rcmdr", dependencies=TRUE)
library(Rcmdr)

in my fresh sage build, and R Commander is working as expected.
Truly great stuff ...
emil
Reply all
Reply to author
Forward
0 new messages