I encountered the same issue a few weeks ago

http://sourceforge.net/mailarchive/message.php?msg_name=1224257111.11195.93.camel%40hot-spring

import array
import rpy2.robjects as ro
import rpy2.rlike.container as rlc

x = ro.RVector(array.array('i', [1,2]))
y = ro.RVector(array.array('i', [3,4]))

tl = rlc.TaggedList([x, y], tags = ('x', 'y'))

dataf = ro.RDataFrame(tl)

Laurent


2008/11/13  <[EMAIL PROTECTED]>:
>
> Hi,
>
> this might be an trivial issue, bu I have trouble twisting my brain enough
> to make this work.
>
> In our python-application (http://sourceforge.net/projects/sensorytool/) we
> use some R-code programmed by a research group we collaborate with. I know
> next to nothing about R, but I made the transfer of arrays from Python to R
> and back work eventually using rpy1 quite some time ago.  We managed to do
> this without needing to save the data to the harddisk and then having to
> read it with R. The code looks awkward I guess, but it worked for us which
> is what mattered. This is the code using rpy1:
>
>
> from rpy import *
> from sensorytools import SensoData
>
> data = SensoData('C:\Work\PanelCheck\Methods\Niels\october\Ost.txt')
> rawScores = data.MatrixData().copy()
> rawLables = data.MatrixLables().copy()
> raw = hstack((rawLables, rawScores))
> atts = data.Attributes()
> lables = data.Lables()
> colNames = lables + atts
>
> # Cannot use attributes list as it is, because strings are in unicode,
> which causes rpy to crash
> # Need to convert unicode-strings to non-unicode strings
> convAtts = []
> for attribute in colNames:
>    convAtts.append(attribute.encode("latin-1"))
>
> # Need to transpose the raw data matrix since rpy transposes it when
> transferring it to an R-data frame
> part = transpose(raw[:,:].copy())
>
> # Constructing the data frame in R
> # Switch to 'no conversion', such that everything that is created now is a
> R object.
> set_default_mode(NO_CONVERSION)
> names = r.get('names<-')
>
> frame = r.data_frame(x=part)
> frame = names(frame, convAtts)
> r.print_(frame)
>
> # Switch back to basic conversion, so that variable "res" (which contains
> the results; see below)
> # will be a python list and not a R object
> set_default_mode(BASIC_CONVERSION)
>
> # Now running Per Brockhoff's R-function to analyse the data in the
> constructed data frame and store
> # results in variable "res"
> r('source("C:/Work/PanelCheck/Methods/Niels/october/sensmixed.R")')
> res = r.sensmixed(frame)
>
>
> Here are the files to make this work for those who would like to try it
> out:
> (See attached file: Ost.txt)(See attached file: sensorytools.py)(See
> attached file: sensmixed.R)
>
>
> Now we are trying to make the switch to rpy2. Using the RDataFrame
> constructor won't do it probably, since the order of the data will be lost.
> That is at least what I understood from the rpy2-documentation.
> Constructing the data frame in R (by using read.table) makes us save the
> numpy array to the harddisk first and then read it again in R via
> read.table(), which is what we would like to avoid.
>
> Is there an obvious way to do this? Is there more information on TaggedList
> instances?
> Any help is much appreciated!
>
>
> BTW, I think you guys do really a great job with rpy!
>
> Cheers
> Oliver
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> rpy-list mailing list
> rpy-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rpy-list
>
>

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to