SCM

[#249] x11() on the Mac

Date:
2008-11-18 09:13
Priority:
2
State:
Closed
Submitted by:
Andreas Felix Hofmann (ahofmann)
Assigned to:
Stefan Theussl (stefan7th)
Hardware:
None
Operating System:
MacOS X
Severity:
minor
URL:
Summary:
x11() on the Mac

Detailed description
Dear Madam or Sir,

I am the admin of the project AquaEnv and I have a question related to the command x11() on the Mac.
My project makes extensive use of the x11() command in the vignette and in the examples which works fine on Linux and Windows, but prompts the error

Warning in x11(width = size[[1]], height = size[[2]]) :
unable to open connection to X11 display ''
Error in X11(d$display, d$width, d$height, d$pointsize, d$gamma, d$colortype, :
unable to start device X11cairo
Calls: plot ... plot.aquaenv -> selectplot -> basicplot -> opendevice -> x11
Execution halted

on the Mac (in the check log downloaded from the R-forge system).
I found on the internet that problems like these are common on the mac and suggested solutions could be to export an enviroment variable like

Sys.putenv("DISPLAY"=":0.0")

I tried that, but on the one hand I do not have a Mac at my disposal to actually check it, and on the other hand it corrupted my Linux and Windows R CMD check runs.

So my questions are:
-) How can I use x11() or something similar on the mac?
-) is there a way of finding out in the code if it is running on mac to
trigger the right commands that will make it work on the mac but would
crash Linux and Windows?

Thank you very much in advance for your help!

With kind regards,
Andreas Hofmann

Comments:

Message  ↓
Date: 2008-11-19 15:14
Sender: Andreas Felix Hofmann

thanks again!

Date: 2008-11-19 15:12
Sender: Stefan Theussl

Definitely.

the mac binary for your package is already available. I triggered the build process manually.

st

Date: 2008-11-19 14:24
Sender: Andreas Felix Hofmann

Sounds great! Thanks a lot!

Just to be sure and recap:
A plain "x11()" in my code without any special "Mac treatment" will now also work on your Mac's?

Thanks again! :-)

Date: 2008-11-19 14:17
Sender: Stefan Theussl

Well, I installed now the latest X11 package from http://xquartz.macosforge.org/ but that didn't help in the first place.

My next idea was to employ X virtual framebuffers which I successfully use under Linux and Bingo! it worked. Without going into further details: Since Leopoard X11.app and hence the DISPLAY environment variable is controlled via launchd. This is convenient if you use the GUI, but not if you connect remotely or use cron jobs (no automatism for launching X11).

The only drawback is an annoying message when the framebuffer is used:
AllocNewConnection: client index = 1, socket fd = 4
Sync Extension 3.0
(EE) XKB: Couldn't open rules file /usr/X11/share/X11/xkb/rules/base
(dix) initialising device 0
(dix) initialising device 1
(dix) initialising device 2
(dix) initialising device 3
(dix) enabling device 0
(dix) enabling device 1
(dix) enabling device 2
(dix) enabling device 3

But for the time being I can live with that.

Best,
Stefan

Date: 2008-11-19 12:42
Sender: Stefan Theussl

Thanks Andreas for bringing this up again, I almost forgot this issue. I couldn't solve this on my last attempt but probably I find a solution now. What I get on our mac when calling .Platform is:
> .Platform
$OS.type
[1] "unix"

$file.sep
[1] "/"

$dynlib.ext
[1] ".so"

$GUI
[1] "X11"

$endian
[1] "little"

$pkgType
[1] "mac.binary"

$path.sep
[1] ":"

$r_arch
[1] "i386"

which basically means that you can check for $pkgType. But it is not nice to set environment variables in a package apart from situations where you cannot avoid this.

We use Leopard on our mac and as Jari already pointed out setting DISPLAY variables should be avoided.

Nevertheless, in my last attempt I simply ignored this advice and added the following line which is now commented out.
#Sys.setenv("DISPLAY"=":10")

As far as I remember I tried different display numbers.

I'll check if I find other options and will come back to you a bit later.

Best,
Stefan

Date: 2008-11-19 09:35
Sender: Andreas Felix Hofmann

tried using an "empty" plot, but I could neither find a way to use "plot" to open a device with a certain size
(even Dalgaard advises to use an explicit call to x11() or some other device: http://tolstoy.newcastle.edu.au/R/help/01a/1595.html) nor to resize an existing plot window (even Ripley advises copying the plot into a NEW device:
https://stat.ethz.ch/pipermail/r-help/2002-October/025859.html).

That means I do absolutely need the explixit x11() call for the Mac. I am really greatefull for any help in this direction!

Thanks a lot in advance!

Date: 2008-11-19 08:55
Sender: Andreas Felix Hofmann

Dear Jari,

thanks for your answer. I am aware that the mac OS is unix, but I found some info on the net that on (apparently some?) Mac's .Platform$OS.type actually has the value "mac". However, I also do not have a Mac at hand to actually try it.

In AquaEnv I defined a plot function for my objects of class aquaenv that can perform all kinds of different plotting tasks using different subfunctions. Furthermore, it takes arguments like e.g. mfrow, size, mgp, mar, oma etc. which are used to set up a new plotting device with the respective properties. All these variables have standard values taylored to an object of type aquaenv. However, there are flags that one can set to make the plot.aquaenv function behave like a "normal" plot function. Furthermore you can set the "device" flag to either "eps" or "pdf" and the plotting will directly be performed into a respective file. To put it in a nutshell, I defined one single plot function that
-) opens a NEW device with a defined size
-) sets parameters like mfrow, mar, oma, mgp etc. in a specific way
-) can also be used to plot to files.

To achieve this goal I perform an explicit opening of either a x11, postscript, or pdf device.... Thus I need the explicit x11() call. (Or something similar on the Mac)

I could, however just try an "empty" plot().... that might actually work...

Thanks again for your help!

Regards,
Andreas Hofmann

Date: 2008-11-19 08:24
Sender: Jari Oksanen

Andreas, I don't remember just now how to check that a system is a Mac (and I don't have a Mac at the moment), but I think I can save you from one failed attempt: I think the .Platform$OS.type =="unix" in Mac (since MacOS is based on BSD). This is a link to an answer Ripley once gave:
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/91292.html

However, x11() should work in Mac, but needs a display set. The piece of advice to explicitly set DISPLAY via Sys.putenv may not be valid any longer. First, I haven't needed that in Mac at leas since R-2.7.0, and Sys.putSenv is Deprecated, and you should use Sys.setenv instead (see corresponding help files in R). However, it seems that you have a very peculiar and nonstandard way of indirect starting of your graphical device. Normally a standard plot() command will launch the needed and available graphical device. I haven't tried your AquaEnv so I can't imagine any reason for your convolute solution.

Date: 2008-11-19 07:49
Sender: Andreas Felix Hofmann

Some follow up information:

I found out that I can determine the system I am running in
by looking into

.Platform$OS.type

and for the mac this variable should have the value "mac" right?!

But then I still do not know what I have to do to open a plot window on the mac...

Thanks in advance for help!

Andreas Hofmann

P.S: The R CMD check log:

Wed Nov 19 05:45:28 2008: Checking package AquaEnv (SVN revision 27) ...
* checking for working pdflatex ... OK
* using log directory '/srv/R/R.check/AquaEnv.Rcheck'
* using R version 2.8.0 (2008-10-20)
* using session charset: ASCII
* checking for file 'AquaEnv/DESCRIPTION' ... OK
* this is package 'AquaEnv' version '0.4'
* checking package name space information ... OK
* checking package dependencies ... OK
* checking if this is a source package ... OK
* checking for executable files ... OK
* checking whether package 'AquaEnv' can be installed ... OK
* checking package directory ... OK
* checking for portable file names ... OK
* checking for sufficient/correct file permissions ... OK
* checking DESCRIPTION meta-information ... OK
* checking top-level files ... OK
* checking index information ... OK
* checking package subdirectories ... OK
* checking R files for non-ASCII characters ... OK
* checking R files for syntax errors ... OK
* checking whether the package can be loaded ... OK
* checking whether the package can be loaded with stated dependencies ... OK
* checking whether the name space can be loaded with stated dependencies ... OK
* checking for unstated dependencies in R code ... OK
* checking S3 generic/method consistency ... OK
* checking replacement functions ... OK
* checking foreign function calls ... OK
* checking R code for possible problems ... OK
* checking Rd files ... OK
* checking Rd cross-references ... OK
* checking for missing documentation entries ... OK
* checking for code/documentation mismatches ... OK
* checking Rd \usage sections ... OK
* checking data for non-ASCII characters ... OK
* creating AquaEnv-Ex.R ... OK
* checking examples ... ERROR
Running examples in 'AquaEnv-Ex.R' failed.
The error most likely occurred in:

> ### * TAfit
>
> flush(stderr()); flush(stdout())
>
> ### Name: TAfit
> ### Title: TAfit
> ### Aliases: TAfit
> ### Keywords: misc
>
> ### ** Examples
>
> ####################################
> # Calculating TA from titration data
> ####################################
>
> #### 1.) proof of concept ##########
> ####################################
> ####################################
>
> # generate "data":
> Tc <- 15
> S <- 35
>
> SumCO2 <- 0.002000
> TA <- 0.002200
> initial_ae <- aquaenv(Tc=Tc, S=S, SumCO2=SumCO2, TA=TA)
>
> mass_sample <- 0.01 # the mass of the sample solution in kg
> mass_titrant <- 0.003 # the total mass of the added titrant solution in
> # kg
> conc_titrant <- 0.01 # the concentration of the
> # titrant solution in mol/kg-soln
> S_titrant <- 0.5 # the salinity of the
> # titrant solution (the salinity of a solution with
> # a ionic strength of 0.01 according to: I = (19.924
> # S) / (1000 - 1.005 S)
> steps <- 20 # the amount of steps the mass of titrant is added in
> type <- "HCl"
>
> ae <- titration(initial_ae, mass_sample, mass_titrant, conc_titrant,
+ S_titrant, steps, type)
>
> plot(ae, ae$delta_mass_titrant, what="pH")
Warning in x11(width = size[[1]], height = size[[2]]) :
unable to open connection to X11 display ''
Error in X11(d$display, d$width, d$height, d$pointsize, d$gamma, d$colortype, :
unable to start device X11cairo
Calls: plot ... plot.aquaenv -> selectplot -> basicplot -> opendevice -> x11
Execution halted
Run time: 29.7 seconds.

Attached Files:

Changes

Field Old Value Date By
status_idOpen2008-12-04 21:30stefan7th
close_date2008-12-04 21:302008-12-04 21:30stefan7th
priority32008-11-19 14:17stefan7th
assigned_tonone2008-11-19 14:17stefan7th
Severitynormal2008-11-19 14:17stefan7th
Thanks to:
Vienna University of Economics and Business Powered By FusionForge