1

I'm feeling awfully silly, but I can't seem to work this out. I'm trying to make a pie chart, using rpy2 in Python.

from rpy2.robjects import r
import os.path

image = "test.png"
values = [0.5, 0.5]

print "using R"
r.png(image, width=100, height=100)
r.pie(values)
r.dev_off()

Now, to do the same thing directly in R I know I want this:

values <- (0.5, 0.5)
pie(values)

That works fine in the R interpreter. I've tried using tuples instead of lists in Python, but was told ValueError: Nothing can be done for the type <type 'tuple'> at the moment.

What Python type corresponds to the R vector? Do I need to use numpy?

4

1 に答える 1

1

[注: あなたの R コードは正しくないようです。あなたはおそらく意味します

values <- c(0.5, 0.5)

関数c()の使用は重要です。下記参照]

現在、rpy2 は、R で Python のリストまたはタプルをどのように表現したいかを推測しようとしません。これは、rpy2 のドキュメントに記載されています。

R 関数c()または rpy2 クラスFloatVectorのいずれかを使用します。

于 2011-09-15T08:09:35.320 に答える