Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
340 views
in Technique[技术] by (71.8m points)

r - Accessing functions with a dot in their name (eg. "as.vector") using rpy2

I am trying to access the "as.vector" R function from within Python, using rpy2. Let's say, for the sake of simplicity, that I want to do something as simple as this using rpy2 (R code):

x <- as.vector(c(1, 2, 3))

Since "as.vector" contains a dot in its name, it is not directly available as a member of rpy2.robjects.r

According to the documentation, rpy2 replaces dots by underscores for named function parameters, but it doesn't seem to work for the function name itself. I tried eg. "as_vector", "asvector" to no avail.

Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

According to the documentation, rpy2 does not replace dots by underscores when using 'rpy2.robjects.r'.

You may want to consider the use of 'importr()'


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...