rpy2

RMagic, IPython and Summary Information

对着背影说爱祢 提交于 2019-12-10 14:53:16
问题 Following the example here http://www.randalolson.com/2013/01/14/filling-in-pythons-gaps-in-statistics-packages-with-rmagic/ I tried the same on a different data set found here, in an IPython notebook. https://github.com/burakbayramli/kod/blob/master/delltest/dell.tgz from pandas import * orders = read_csv("dell.csv",sep=",") %load_ext rmagic %R -i orders print(summary(orders)) I get Length Class Mode [1,] 25 -none- list [2,] 25 -none- list [3,] 25 -none- list .. However the same in R data <-

converting a Python list to an R numeric vector

落花浮王杯 提交于 2019-12-10 11:57:59
问题 I need to fit my data into a Beta distribution and retrieve the alpha parameter. I've been coding in Python, but there doesn't seem to be any beta fitting function in SciPy. Either I do everything in Matlab, which I'm not too familiar with, or in Python with R and its fitdistr function. So I went for the latter. from rpy2.robjects.packages import importr MASS = importr('MASS') Then I take my numpy vector of floats in the range [0,1) and I pass it to fitdistr : myVector = myVector.tolist()

%load_ext rpy2.ipython Image not found error

我的梦境 提交于 2019-12-10 10:04:44
问题 I am trying to use the magic command in ipython, something I saw here: rpy2 slides I have done the following: import rpy2.ipython %load_ext rpy2.ipython But I get the following error: ImportError: dlopen(/Users/XXX/anaconda/lib/python2.7/site-packages/rpy2/rinterface/_rinterface.so, 2): Library not loaded: libicuuc.54.dylib Referenced from: /Users/XXX/anaconda/lib/python2.7/site-packages/rpy2/rinterface/_rinterface.so Reason: image not found Some relevant information: OS: MacOS Sierra Python:

creating multiple scatter plots with same axes in R

浪尽此生 提交于 2019-12-10 08:59:20
问题 I'm trying to plot four scatter plots in 2 x 2 arrangement in R (I'm actually plotting via rpy2). I'd like each to have an aspect ratio of 1 but also be on the same scale, so identical X and Y ticks for all the subplots so that they can be compared. I tried to do this with par : par(mfrow=c(2,2)) # scatter 1 plot(x, y, "p", asp=1) # scatter 2 plot(a, b, "p", asp=1) # ... Edit: Here's a direct example of what I have now: > par(mfrow=c(2,2)) > for (n in 1:4) { plot(iris$Petal.Width, rnorm

How to Install rpy2 on Mac OS X

一世执手 提交于 2019-12-09 18:13:30
问题 I am trying, so far unsuccessfully, at installing the rpy2 for python on my Mac OSX. I have tried Macports and DarwinPorts but have had no luck with import rpy2 within the python shell environment. I don't know much about programming in Mac and I am a wiz at installing modules on a Windoze based system, but for the life of me cannot do a simple port on my Mac at home. What I am after, if someone would be so kind, are "dumbed down" instructions for a successful install of rpy2 for Mac OSX Snow

Passing vectors and params from Python to R functions

此生再无相见时 提交于 2019-12-08 20:44:33
I am learning Python and R and am having an issue passing parameters from Python to an R function named "Contours". The below works..... Python (testr.py) import rpy2.robjects as robjects robjects.r(''' source('Wrapper.R') ''') r_myfunc = robjects.globalenv['Contours'] r_myfunc() R (Wrapper.R) source ('./DrawCompRecVark.R') imageDirectory="./tmp/" Contours <- function() { k=c(0,1) sens=c(0.8, 0.9, 0.95, 0.995) spec=0.8 prev=0.001 N=1 uniqueId=1 #graph prepareSaveGraph(imageDirectory, "PPVkSensSpec-", uniqueId) DrawSensSpec(k, sens, spec, prev, N) dev.off() #save the cNPV graph prepareSaveGraph

Calling R functions in rpy2 error - “argument is missing”

▼魔方 西西 提交于 2019-12-08 11:17:44
问题 I'm facing some issues in using rpy2 package in Python. Actually, I am trying to call a function called upliftRF (of the library "uplift" in R) by passing some arguments. As stated on page 27 of https://cran.r-project.org/web/packages/uplift/uplift.pdf, one of the arguments of the function can be x or a formula that describes the model to fit based on a dataframe ("data" parameter in arguments). When executing the code of page 29 in R, everything is running without any problems. However, I

ggplot2 not present in rpy2 for python?

亡梦爱人 提交于 2019-12-08 07:37:46
问题 I am working with rpy2 v2.1.9 in Python3.2, I don't understand why I can't use the library ggplot2 import rpy2 from rpy2.robjects import r r.library("ggplot2") Here is the error message I got Error in function (package, help, pos = 2, lib.loc = NULL, character.only = FALSE, : there is no package called 'ggplot2' Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.2/dist-packages/rpy2/robjects/functions.py", line 82, in __call__ return super

rpy2 fails to import 'rgl' R package

痴心易碎 提交于 2019-12-08 06:09:21
问题 To load the rgl package check if the rgl package is installed in R from within python , I'm combining the recipes given in these two questions: rpy2: check if package is installed rpy2 importr failing with xts and quantmod Here's the MWE I put together: from rpy2.rinterface import RRuntimeError from rpy2.robjects.packages import importr utils = importr('utils') def importr_tryhard(packname, contriburl): try: if packname == 'rlg': rgl = importr("rgl", robject_translations = {".rgl.abclines": "

Can I connect an external (R) process to each pyspark worker during setup

最后都变了- 提交于 2019-12-08 06:02:13
问题 I want to have each python worker start an R shell using rpy2. Can I do this during some sort of setup phase similar to how I assume this would happen when you import a Python module to be used for later executor tasks? For example: import numpy as np df.mapPartitions(lambda x: np.zeros(x)) In my case I want to instead start an R shell on each executor and import R libraries, which would look something like this: import rpy2.robjects as robjects from rpy2.robjects.packages import importr