Revision: 653
http://rpy.svn.sourceforge.net/rpy/?rev=653&view=rev
Author: lgautier
Date: 2008-09-11 07:08:55 +0000 (Thu, 11 Sep 2008)
Log Message:
-----------
initOptions is now initoptions.
get_initoptions and setinitoptions were added and are the way
to play with the options used to initialize the embedded R.
Modified Paths:
--------------
branches/rpy_nextgen/NEWS
branches/rpy_nextgen/doc/source/rinterface.rst
branches/rpy_nextgen/rpy/rinterface/rinterface.c
branches/rpy_nextgen/rpy/rinterface/tests/test_EmbeddedR.py
Modified: branches/rpy_nextgen/NEWS
===================================================================
--- branches/rpy_nextgen/NEWS 2008-09-11 07:05:51 UTC (rev 652)
+++ branches/rpy_nextgen/NEWS 2008-09-11 07:08:55 UTC (rev 653)
@@ -10,7 +10,10 @@
- defined `names` as a property for :class:`RVector`
+:mod:`rpy2.rinterface`:
+- added functions :func:`get_initoptions` and :func:`set_initoptions`.
+
Changes
-------
@@ -22,6 +25,9 @@
- :func:`sexpTypeEmbeddedR` is now called :func:`str_typeint`.
+- :attr:`initOptions` is now called :attr:`initoptions`. Changes of options
can only be done through :func:`set_initoptions`.
+
+
Bugs fixed
----------
Modified: branches/rpy_nextgen/doc/source/rinterface.rst
===================================================================
--- branches/rpy_nextgen/doc/source/rinterface.rst 2008-09-11 07:05:51 UTC
(rev 652)
+++ branches/rpy_nextgen/doc/source/rinterface.rst 2008-09-11 07:08:55 UTC
(rev 653)
@@ -44,9 +44,13 @@
To avoid unpredictable results when using the embedded R,
subsequent calls to :func:`initr` will not have any effect.
-Parameters for the initialization are in the module variable
-`initOptions`.
+The functions :func:`get_initoptions` and :func:`set_initoptions`
+can be used to modify the options.
+Default parameters for the initialization are otherwise
+in the module variable `initoptions`.
+
+
.. index::
single: initialize R_HOME
Modified: branches/rpy_nextgen/rpy/rinterface/rinterface.c
===================================================================
--- branches/rpy_nextgen/rpy/rinterface/rinterface.c 2008-09-11 07:05:51 UTC
(rev 652)
+++ branches/rpy_nextgen/rpy/rinterface/rinterface.c 2008-09-11 07:08:55 UTC
(rev 653)
@@ -81,7 +81,7 @@
-/* A sequence that holds options to initialize R */
+/* A tuple that holds options to initialize R */
static PyObject *initOptions;
/* Helper variables to quickly resolve SEXP types.
@@ -306,6 +306,39 @@
/* --- Initialize and terminate an embedded R --- */
+static PyObject* EmbeddedR_getinitoptions(PyObject *self)
+{
+ return initOptions;
+}
+PyDoc_STRVAR(EmbeddedR_get_initoptions_doc,
+ "\
+Get the options used to initialize R.\
+");
+
+static PyObject* EmbeddedR_setinitoptions(PyObject *self, PyObject *tuple)
+{
+
+ if (embeddedR_status & RPY_R_INITIALIZED) {
+ PyErr_Format(PyExc_RuntimeError,
+ "Options cannot be set once R has been initialized.");
+ return NULL;
+ }
+
+ int istuple = PyTuple_Check(tuple);
+ if (! istuple) {
+ PyErr_Format(PyExc_ValueError, "Parameter should be a tuple.");
+ return NULL;
+ }
+ Py_DECREF(initOptions);
+ Py_INCREF(tuple);
+ initOptions = tuple;
+ return Py_None;
+}
+PyDoc_STRVAR(EmbeddedR_set_initoptions_doc,
+ "\
+Set the options used to initialize R.\
+");
+
static PyObject* EmbeddedR_init(PyObject *self)
{
@@ -323,7 +356,7 @@
PyObject *opt_string;
Py_ssize_t ii;
for (ii = 0; ii < n_args; ii++) {
- opt_string = PyList_GetItem(initOptions, ii);
+ opt_string = PyTuple_GetItem(initOptions, ii);
options[ii] = PyString_AsString(opt_string);
}
@@ -2367,6 +2400,12 @@
/* --- List of functions defined in the module --- */
static PyMethodDef EmbeddedR_methods[] = {
+ {"get_initoptions", (PyCFunction)EmbeddedR_getinitoptions,
+ METH_NOARGS,
+ EmbeddedR_get_initoptions_doc},
+ {"set_initoptions", (PyCFunction)EmbeddedR_setinitoptions,
+ METH_O,
+ EmbeddedR_set_initoptions_doc},
{"initr", (PyCFunction)EmbeddedR_init, METH_NOARGS,
EmbeddedR_init_doc},
{"endr", (PyCFunction)EmbeddedR_end, METH_O,
@@ -2528,25 +2567,28 @@
return;
d = PyModule_GetDict(m);
- initOptions = PyList_New(4);
+ initOptions = PyTuple_New(4);
+
+ /* Add an extra ref. It should remain impossible to delete it */
PYASSERT_ZERO(
- PyList_SetItem(initOptions, 0,
- PyString_FromString("rpy2"))
+ PyTuple_SetItem(initOptions, 0,
+ PyString_FromString("rpy2"))
);
PYASSERT_ZERO(
- PyList_SetItem(initOptions, 1,
- PyString_FromString("--quiet"))
+ PyTuple_SetItem(initOptions, 1,
+ PyString_FromString("--quiet"))
);
PYASSERT_ZERO(
- PyList_SetItem(initOptions, 2,
- PyString_FromString("--vanilla"))
+ PyTuple_SetItem(initOptions, 2,
+ PyString_FromString("--vanilla"))
);
PYASSERT_ZERO(
- PyList_SetItem(initOptions, 3,
- PyString_FromString("--no-save"))
+ PyTuple_SetItem(initOptions, 3,
+ PyString_FromString("--no-save"))
);
- PyModule_AddObject(m, "initOptions", initOptions);
+ PyModule_AddObject(m, "initoptions", initOptions);
+ Py_INCREF(initOptions);
PyModule_AddObject(m, "Sexp", (PyObject *)&Sexp_Type);
PyModule_AddObject(m, "SexpClosure", (PyObject *)&ClosureSexp_Type);
Modified: branches/rpy_nextgen/rpy/rinterface/tests/test_EmbeddedR.py
===================================================================
--- branches/rpy_nextgen/rpy/rinterface/tests/test_EmbeddedR.py 2008-09-11
07:05:51 UTC (rev 652)
+++ branches/rpy_nextgen/rpy/rinterface/tests/test_EmbeddedR.py 2008-09-11
07:08:55 UTC (rev 653)
@@ -1,4 +1,5 @@
import unittest
+import itertools
import rpy2.rinterface as rinterface
rinterface.initr()
@@ -41,6 +42,16 @@
def testStr_typeint_invalid(self):
self.assertRaises(LookupError, rinterface.str_typeint, 99)
+ def testGet_initoptions(self):
+ options = rinterface.get_initoptions()
+ self.assertEquals(len(rinterface.initoptions),
+ len(options))
+ for o1, o2 in itertools.izip(rinterface.initoptions, options):
+ self.assertEquals(o1, o2)
+
+ def testSet_initoptions(self):
+ self.assertRaises(RuntimeError, rinterface.set_initoptions,
+ ('aa', '--verbose', '--no-save'))
class ObjectDispatchTestCase(unittest.TestCase):
def testObjectDispatchLang(self):
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
rpy-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rpy-list