Manifold/R Integration
From Manipedia
R can be tightly integrated into a workflow with Manifold in a variety of ways. The simplest involve methods of transferring data between the two environments.
The most useful application for this is when you have some existing R code that you know will run, and you want it to work from within Manifold. More interactive connections are trickier as they rely on both knowledge of R and advanced scripting in Manifold.
If you have no knowledge of R or why it is useful for statistics (amongst other things), here is a simple description of linear models via formula.
If the variable "d" in R is a data.frame with columns "x" and "y" (analogous to a table in Manifold) then the following formula expression provides a basic regression of x vs. y.
reg <- lm(y ~ x, data = d)
Formulas can specify any linear model you want, and on a similar foundation you'll find practically any statistical formulation in R somewhere.
See http://www.r-project.org/ for full details on R.
Contents |
[edit] Transfer table data from Manifold into R
There are four main methods for reading data into R that originated in Manifold.
- External text file exported from Manifold:
d <- read.csv("C:/temp/file.csv") - Copy and paste via the clipboard:
d <- read.delim("clipboard") will read data from a table/selection copied in Manifold. - Directly from a .map file using ODBC
Using the function defined here, and the RODBC package- open a connection to the file
library(RODBC)
ch <- odbcConnectManifold("C:/temp/world.map") - pass a Manifold query to the connection
d <- sqlQuery(ch, "SELECT [Longitude (I)] AS lon, [Latitude (I)] AS lat, [Capital] AS name FROM [Countries] WHERE [Area (I)] > 150;")
- open a connection to the file
- Directly from a COM connection (advanced)
See this thread for more details: http://forum.manifold.net/forum/t59964.13
[edit] Transfer Shape File (exported from Manifold) into R
There are several packages which allow you to import Shape Files into R:
- Using the rgdal package, needs to be installed by going to the relevant CRAN Archive:
>library(rgdal)
>dataset <- readOGR(".","ShapeFileName")
- Using the maptools package. Need to specify geometry type at import:
>library(maptools)
>dataset <- readShapePoints("ShapFileName.shp")
[edit] Further mechanisms
The R package rgdal (very easily installed with install.packages("rgdal") ) can read directly from shapefiles, GeoTIFFs, and a large variety of spatial formats. See GDAL raster formats and GDAL vector formats for details]
TODO: The ODBC driver in GDAL can also read directly from .map files, but up until recently some bugs on both sides made this problematic.
It is not clear what steps to take first for more tight coupling of R and Manifold: there is a lot that can be done via customizations within Manifold (and R) for the particular uses needed. See this post and the thread it is part of for more discussion, and get your suggestions in!
R/Scilab (D)COM Server provides a COM-Interface to R as well as various COM objects and Active X controls for your applications. Additionally, an Add-In for Microsoft Excel is provided to easily use R in Excel and create statistical applications with Excel as the main GUI. The main features of this package are:
- COM server for local and remote use of R and Scilab
- transfer of data into/from R, including NA, NaN,...
- Active X Controls for text and graphics output
- Repository for R instances for shared and exclusive access
- Excel Add-In (available for separate download from http://rcom.univie.ac.at/)
If you have installed the package, you can then simply write a script as follows:
//Initialise R(D)Com Oject var R = new ActiveXObject("StatConnectorSrv.StatConnector"); //Start R Interface R.Init("R"); //Evaluate Command Set var a = R.Evaluate("2+2"); Application.Messagebox(a);
[edit] User forum threads of interest
[edit] Interesting external resources
- Applied Spatial Data Analysis with R Bivand, Roger S., Pebesma, Edzer J., Rubio, Virgilio Gómez, 2008, Approx. 400 p., ISBN: 978-0-387-78170-9
- CRAN Task View: Analysis of Spatial Data
- R Wiki Spatial Data Page
- Quick-R online tutorials for SAS/SPSS/Stata Users
- Gstat for multivariable geostatistical modelling, prediction and simulation
- Analysing spatial point patterns in R





