Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: Complete R interface section #7309

Closed
wants to merge 1 commit into from
Closed

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented Jun 2, 2014

Currently, "rpy2 R interface" documentation has blank section. Added descriptions to cover required basic topics.

@jreback jreback added the Docs label Jun 2, 2014
@jreback jreback added this to the 0.14.1 milestone Jun 2, 2014
@jorisvandenbossche
Copy link
Member

@sinhrks Great to work on this! (it was a little bit a stub page now)

But I am not sure of the current status of how the conversion should be preferably done. Eg see http://stackoverflow.com/questions/20630121/pandas-how-to-convert-r-dataframe-back-to-pandas, I don't know if convert_to_r_dataframe is still needed (with the newer rpy2)

@sinhrks
Copy link
Member Author

sinhrks commented Jun 2, 2014

Thanks. I've used rpy 2.3.8 and will check 2.4.0 spec.

@jorisvandenbossche
Copy link
Member

If I look at the rpy2 docs, it seems this conversion machinery pandas2ri was already there from 2.3.3, although there were some changes in 2.4

@jreback
Copy link
Contributor

jreback commented Jun 6, 2014

@jorisvandenbossche I am ok with this

@sinhrks
Copy link
Member Author

sinhrks commented Jun 7, 2014

I've briefly checked pandas2ri of rpy2.4.0, and found current pandas conversion looks better. pandas2ri doesn't convert returned rpy2 DataFrame automatically, and may raise ValueError for DatetimeIndex.

But it is good if we don't have to care about rpy2 instances. I think it can be achieved by simple wrapper on pandas.rpy2.common, and will issue a PR for this.

import pandas as pd
import pandas.rpy.common as com
import rpy2.robjects as ro
from rpy2.robjects import pandas2ri

pandas2ri.activate()

iris = com.load_data('iris')
ro.r.assign('iris', iris)
returned = ro.r['iris']
type(returned)
# <class 'rpy2.robjects.vectors.DataFrame'>

df = pd.DataFrame(np.random.randn(20, 5),
                  index=pd.date_range(start='2011/01/01', freq='D', periods=20))
ro.r.assign('df', df)
returned = ro.r['df']
# ValueError: Unknown numpy array type.

@jorisvandenbossche
Copy link
Member

Something else, but maybe somewhat orthogonal to this PR, I think we could also mention the IPython rmagic in this doc page.

@davclark
Copy link
Contributor

davclark commented Jun 8, 2014

Note rpy2 2.4+ is now the blessed "proper" location to get the rmagic via:

%load_ext rpy2.ipython

The updated rmagic lives in that sub-package in rpy2.

@jreback
Copy link
Contributor

jreback commented Jun 17, 2014

@jorisvandenbossche merge when happy with this

It is easier to use ``rpy2.robjects`` directly to call R functions.
You can retrieve R object (including R function) from R namespace by dictionary access of ``robjects.r``.

Below example shows to retrieve R's **sum** function and pass ``rpy2.robjects.vecrtor.DataFrame``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Below example shows how to retrieve ...' + 'vecrtor' -> 'vector'

@jorisvandenbossche
Copy link
Member

I think it depends a bit on the outcome of #7385?

@jreback jreback modified the milestones: 0.15.0, 0.14.1 Jun 30, 2014
@jreback
Copy link
Contributor

jreback commented Jun 30, 2014

@sinhrks ok, deferring this to outcome of #7385

or if you want to document the current, then you can change (or submit a new one).

@jreback
Copy link
Contributor

jreback commented Mar 8, 2015

let's redirect to rpy2 for conversions, see #9602

@jreback jreback closed this Mar 8, 2015
@sinhrks sinhrks deleted the rdoc branch March 31, 2015 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants