Hi,
Thanks for the response. That code sequence works for me too.
I did find the following post:
http://sourceforge.net/mailarchive/message.php?msg_id=28198698
The '**{'na.rm': True}' syntax worked for me.
Apart from the odd thing like this, the rpy2 system has been working pretty
nicely for me. The graphics integration in particular has been really valuable.
It seems like R's strong suit is not data pre-processing and general scripting,
so I'm grateful to Laurent for providing this system.
Thanks,
Nick
From: Peng Lian <janusl...@126.com<mailto:janusl...@126.com>>
Reply-To: "RPy help, support and design discussion list"
<rpy-list@lists.sourceforge.net<mailto:rpy-list@lists.sourceforge.net>>
Date: Monday, April 29, 2013 11:50 PM
To: "RPy help, support and design discussion list"
<rpy-list@lists.sourceforge.net<mailto:rpy-list@lists.sourceforge.net>>
Subject: Re: [Rpy] Help with passing 'na.rm' to R functions?
Nick,
I think you can use *SignatureTranslatedFunction* to translate argument na.rm
to na_rm. I replicated your example as follows:
from rpy2.robjects.packages import importr
from rpy2.robjects.functions import SignatureTranslatedFunction
base = importr('base')
base.max = SignatureTranslatedFunction(base.max, init_prm_translate={'na_rm':
'na.rm'})
data_series = robjects.IntVector( [1, 7, robjects.NA_Integer, 9, 2])
print(data_series)
[1] 1 7 NA 9 2
print(base.max(data_series, na_rm=True))
[1] 9
So it works
I'm new in RPy2, and i don't know some simple method to do this.
Peng Lian
At 2013-04-30 09:48:45,"Pavey, Nicholas"
<npa...@akamai.com<mailto:npa...@akamai.com>> wrote:
Hi Rpy2 users,
I'm having some difficulty passing the 'na.rm' parameter to the R 'max'
function. I'm pretty new to rpy2, so I'm sure it's something obvious I'm
missing.
I have referred to the documentation on this subject, here:
http://rpy.sourceforge.net/rpy2/doc-2.2/html/robjects_functions.html
I also tried searching the mailing list archive, but didn't come across an
answer.
Here's my test source:
from rpy2 import robjects
from rpy2.robjects.packages import importr
data_series = robjects.IntVector( [1, 7, robjects.NA_Integer, 9, 2])
print data_series
# Note – I am using the underscore convention here, as
# suggested in the rpy2 documentation.
val = robjects.r.max(data_series, na_rm = True)
print val
Additionally, I tried the 'base' approach described in the docs, with the same
problem:
from rpy2 import robjects
from rpy2.robjects.packages import importr
base = importr('base')
data_series = robjects.IntVector( [1, 7, robjects.NA_Integer, 9, 2])
print data_series
val = base.max(data_series, na_rm = True)
print val
I'm always getting 'NA' as the result, regardless of whether I set 'na_rm' to
True or False (or 1 or zero, too).
The 'max' function does work as expected without the 'NA' object in the data
series.
Here are my version numbers:
OS : Ubuntu 10.04 LTS, Intel x86_64
Python version : 2.7.4
R version: 2.15.3
Rpy2 version : 2.3.5
By the way, I am constrained to use Python 2.7.x, rather than Python 3.
What am I doing wrong here?
Thanks for your help,
Nick
------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list