On Mon, 2009-04-27 at 16:26 +0200, Toby HOCKING wrote:
> One more thing: in R it seems accent strings have the encoding "UTF-8"
> whereas python strings come into R always with an unknown encoding.
> Maybe this has something to do with it?
>
> thock...@stagiaire-desktop:~/rpy$ R
> > Encoding("c")
> [1] "unknown"
> > Encoding("ç")
> [1] "UTF-8"
>
> thock...@stagiaire-desktop:~/rpy$ python
> >>> from rpy import r
> >>> r.plot(1,2,main="ç")
> >>> r.Encoding("c")
> 'unknown'
> >>> r.Encoding(u"c")
> 'unknown'
> >>> r.Encoding("ç")
> 'unknown'
> >>> r.Encoding(u"ç")
>
> *** caught segfault ***
> address 0x4, cause 'memory not mapped'
>
> Possible actions:
> 1: abort (with core dump, if enabled)
> 2: normal R exit
> 3: exit R without saving workspace
> 4: exit R saving workspace
> Selection: 2
> Exception thread.error: 'release unlocked lock' in <class
> 'thread.error'> ignored
> thock...@stagiaire-desktop:~/rpy$
>
Unicode support in rpy (and rpy2) is not complete.
rpy2 has a similar behavior (except regarding the segmentation fault).
>>> import rpy2.robjects as ro
>>> ro.r.Encoding(u"ç")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/usr/local/packages/python-libs/lib/python2.5/site-packages/rpy2/robjects/__init__.py",
line 418, in __call__
new_args = [conversion.py2ri(a) for a in args]
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe7' in
position 0: ordinal not in range(128)
>>> print(ro.r.Encoding('ç'))
[1] "unknown"
In the meantime, non-ascii characters can otherwise be used without
trouble:
>>> print(ro.r.sub('ç', '***', 'aaaçbbb'))
[1] "aaa***bbb"
Or in a plot
ro.r.plot(range(10), range(10), xlab='', ylab='', type = 'n')
ro.r.text(ro.r.runif(10, 1, 9), ro.r.runif(10, 1, 9), 'ç')
L.
>
> ------------------------------------------------------------------------------
> Crystal Reports - New Free Runtime and 30 Day Trial
> Check out the new simplified licensign option that enables unlimited
> royalty-free distribution of the report engine for externally facing
> server and web deployment.
> http://p.sf.net/sfu/businessobjects
> _______________________________________________
> rpy-list mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/rpy-list
------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations
Conference from O'Reilly Media. Velocity features a full day of
expert-led, hands-on workshops and two days of sessions from industry
leaders in dedicated Performance & Operations tracks. Use code vel09scf
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
_______________________________________________
rpy-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rpy-list