Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8250751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:00:16+00:00 2026-06-08T00:00:16+00:00

I am using the rpy2 package to bring some R functionality to python. The

  • 0

I am using the rpy2 package to bring some R functionality to python.
The functions I’m using in R need a data.frame object, and by using rlike.TaggedList and then robjects.DataFrame I am able to make this work.

However I’m having performance issues, when comparing to the exact same R functions with the exact same data, which led me to try and use the rpy2 low level interface as mentioned here – http://rpy.sourceforge.net/rpy2/doc-2.3/html/performances.html

So far I have tried:

  1. Using TaggedList with FloatSexpVector objects instead of numpy arrays, and the DataFrame object.
  2. Dumping the TaggedList and DataFrame classes by using a dictionary like this:

    d = dict((var_name, var_sexp_vector) for ...)
    dataframe = robjects.r('data.frame')(**d)
    

Both did not get me any noticeable speedup.

I have noticed that DataFrame objects can get a rinterface.SexpVector in their constructor , so I have thought of creating a such a named vector, but I have no idea on how to put in the names (in R I know its just names(vec) = c(‘a’,’b’…)).

How do I do that? Is there another way?
And is there an easy way to profile rpy itself, so I could know where the bottleneck is?

EDIT:

The following code seem to work great (x4 faster) on newer rpy (2.2.3)

data = ro.r('list')([ri.FloatSexpVector(x) for x in vectors])[0]
data.names = ri.StrSexpVector(vector_names)

However it doesn’t on version 2.0.8 (last one supported by windows), since R cant seem to be able to use the names: “Error in eval(expr, envir, enclos) : object ‘y’ not found”

Ideas?

EDIT #2:
Someone did the fine job of building a rpy2.3 binary for windows (python 2.7), the mentioned works great with it (almost x6 faster for my code)

link: https://bitbucket.org/breisfeld/rpy2_w32_fix/issue/1/binary-installer-for-win32

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T00:00:17+00:00Added an answer on June 8, 2026 at 12:00 am

    Python can be several times faster than R (even byte-compiled R), and I managed to perform operations on R data structures with rpy2 faster than R would have. Sharing the relevant R and rpy2 code would help make more specific advice (and improve rpy2 if needed).

    In the meantime, SexpVector might not be what you want; it is little more than an abstract class for all R vectors (see class diagram for rpy2.rinterface). ListSexpVector might be more appropriate:

    import rpy2.rinterface as ri
    ri.initr()
    l = ri.ListSexpVector([ri.IntSexpVector((1,2,3)),
                           ri.StrSexpVector(("a","b","c")),])
    

    An important detail is that R lists are recursive data structures, and R avoids a catch 22-type of situation by having the operator “[[” (in addittion to “[“). Python does not have that, and I have not (yet ?) implemented “[[” as a method at the low-level.

    Profiling in Python can be done with the module stdlib module cProfile, for example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using rpy2 to do data analysis and plotting in python. It works fine
Actually I'm using R + Python with RPY2 to manipulate data and ggplot to
I'm using R in my Python script through the rpy2 library and I need
I am trying to install some software on a Linux machine (python's rpy2 package,
I am trying to run a simple linear regression (using rpy2 from Python) and
I am using rpy2 for regressions. The returned object has a list that includes
I am trying to access the as.vector R function from within Python, using rpy2.
i am using rpy2-2.0.7 (i need this to work with windows 7, and compiling
I am hoping to port some Python code that uses RPY2 to run R
I've just started using rpy2 with Python. I've installed it and am able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.