rpy2 の引数リストを取得
- 今回は、統計解析ソフト R を Python で使うためのモジュール rpy2 に対して使った。
- クラスタリング kmeans で最大試行数の設定は、R では「iter.max」を使う。
- しかし、Python で「iter.max」として指定するとエラーになった!!
- 「inspect.getmembers」で調べた。
$ python
>>> import inspect
>>> import rpy2.robjects as ro
>>> clusteringFunc = ro.r["kmeans"]
>>> inspect.getmembers( clusteringFunc )
[('_Function__assymbol', ), ('_Function__call', ), ('_Function__formals', ), ('_Function__local', ), ('_Function__newenv', ), ('_RObjectMixin__close', ), ('_RObjectMixin__fifo', ), ('_RObjectMixin__file', ), ('_RObjectMixin__rclass', ), ('_RObjectMixin__rclass_set', ), ('_RObjectMixin__readlines', ), ('_RObjectMixin__show', ), ('_RObjectMixin__sink', ), ('_RObjectMixin__tempfile', ), ('_RObjectMixin__unlink', ), ('__call__', >), ('__class__', ), ('__deepcopy__', ), ('__delattr__', ), ('__dict__', {'__rname__': 'kmeans', '_local_env': , '_prm_translate': {'iter_max': 'iter.max'}}), ('__doc__', " Python representation of an R function such as \n the character '.' is replaced with '_' whenever present in the R argument name. "), ('__format__', ), ('__getattribute__', ), ('__getstate__', ), ('__hash__', ), ('__init__', >), ('__module__', 'rpy2.robjects.functions'), ('__new__', ), ('__reduce__', ), ('__reduce_ex__', ), ('__repr__', ), ('__rname__', 'kmeans'), ('__setattr__', ), ('__setstate__', ), ('__sexp__', ), ('__sexp_refcount__', 2), ('__sizeof__', ), ('__str__', >), ('__subclasshook__', ), ('__weakref__', None), ('_local_env', ), ('_prm_translate', {'iter_max': 'iter.max'}), ('_rclass_get', >), ('_rclass_set', >), ('closureenv', ), ('do_slot', ), ('do_slot_assign', ), ('formals', >), ('named', 2), ('r_repr', >), ('rcall', >), ('rclass', ), ('rsame', ), ('typeof', 3)]
- 長~いが、中に「iter_max:iter.max」があり、「iter_max」を使えば良いことが分かった。