Noel Mulvihill
2008-Sep-25 04:06 UTC
[Rd] C++ & R: Displaying a lattice graphic using D Com
Dear list members, When I modify the MFC sample (using the statconnector graphics device) to show a lattice graph in the Active X control (actually the wireframe from http://addictedtor.free.fr/graphiques/graphcode.php?graph=40 ) the program runs without generating any errors, but the data-driven part of the plot does not display. The bounding box is displayed, but not the axes or data within it. The same code executes perfectly when typed directly into R, so this is an issue with my code. Sometimes the plot 'flickers' into view or partial view very briefly, before execution has completed. However, once the code has executed no plot is visible. I am using visual C++ - and I have copied out the code at the end of this note. I would be grateful for any advice. Kind regards Noel void CMFCClientDlg::OnTest() { BeginWaitCursor(); IStatConnector lConnector; IDispatch* lCharDev = NULL; IDispatch* lGfxDev = NULL; if(FAILED(m_CharDev.GetControlUnknown()->QueryInterface(IID_IDispatch,(LPVOI D*) &lCharDev))) { MessageBox("Error querying Dispatch from Character Device"); return; } if(FAILED(lConnector.CreateDispatch(_T("StatConnectorSrv.StatConnector")))) { MessageBox("Error creating StatConnectorSrv"); return; } lConnector.Init(_T("R")); lConnector.SetCharacterOutputDevice(lCharDev); lConnector.AddGraphicsDevice(_T("Gfx"),m_GraphDev.GetGFX()); lConnector.EvaluateNoReturn(_T("require(lattice)")); lConnector.EvaluateNoReturn(_T("x <- seq(-pi, pi, len = 20)")); lConnector.EvaluateNoReturn(_T("y <- seq(-pi, pi, len = 20)")); lConnector.EvaluateNoReturn(_T("g <- expand.grid(x = x, y = y)")); lConnector.EvaluateNoReturn(_T("g$z <- sin(sqrt(g$x^2 + g$y^2))")); lConnector.EvaluateNoReturn(_T("plot(wireframe(z ~ x * y, g, drape = TRUE, aspect = c(3,1), colorkey = TRUE))")); lConnector.Close(); EndWaitCursor(); }