rpy2

rpy2 - 'R' object has no attribute 'nls'

随声附和 提交于 2019-12-11 05:25:34
问题 I am using rpy2 to do some non-linear regression in r from python. import rpy2.robjects as robjects from rpy2.robjects import DataFrame, Formula from rpy2.robjects import r import rpy2.robjects.numpy2ri as npr import numpy as np from rpy2.robjects.packages import importr r.nls(rates * 1-(1/(10^(a * count ^ (b-1)))), weights=count, start=list(a=a, b=b)) I have the following errors: LookupError: 'nls' not found AttributeError: 'R' object has no attribute 'nls' It is also calling '~' as invalid

fitdistr in rpy2

有些话、适合烂在心里 提交于 2019-12-11 04:09:53
问题 I've a 1D list of data, that I want to fit into a distribution using either least squares or maximum likelihood, as presented here, but I want to do it from python instead of the R interactive shell. I got rpy2 installed, and would like to use the fitdistr function from within the interactive ipython shell, as I have imported the data in a list. Where is this function, and how do I use it? 回答1: The function is in the R package MASS from rpy2.robjects.packages import importr MASS = importr(

rpy2 Error: “unrecognized escape in character string”

大兔子大兔子 提交于 2019-12-11 04:08:08
问题 I have a chunk of code in R that I would like to insert in my python code. To that aim I am using rpy2. The R code involves many regular expressions and it seems that rpy2 is not handling them correctly or perhaps I am not coding them adequately. Here is an example of a piece of code that words and another that does not work: 1) It works : A very trivial removeStopWords function: import rpy2.robjects as robjects from rpy2.robjects.packages import importr robjects.r(''' library(data.table)

What object to pass to R from rpy2?

故事扮演 提交于 2019-12-11 03:39:01
问题 I'm unable to make the following code work, though I don't see this error working strictly in R. from rpy2.robjects.packages import importr from rpy2 import robjects import numpy as np forecast = importr('forecast') ts = robjects.r['ts'] y = np.random.randn(50) X = np.random.randn(50) y = ts(robjects.FloatVector(y), start=robjects.IntVector((2004, 1)), frequency=12) X = ts(robjects.FloatVector(X), start=robjects.IntVector((2004, 1)), frequency=12) forecast.Arima(y, xreg=X, order=robjects

Wrap R function in python

随声附和 提交于 2019-12-11 02:54:17
问题 I would like to wrap a R function contained in a package princurve. With ipython I do it successfully with an ipython cell R magic: %%R -i X -o s,lambda fit1<-principal.curve(X) s <- fit1$s l <- fit1$lambda but I want a function that I can import from a module like: from mymodule import principal_curve s, l = principal_curve(X) I guess I have to use rpy directly, I am not sure how... 回答1: I don't use R but using this example in the docs you can define a function and import it into a python

Visual Studio cl.exe error in installing rpy2

北战南征 提交于 2019-12-11 02:33:34
问题 I am installing rpy2 in Django and got the following errors. C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -I.\rpy\rinterface "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\include" /Tc.\rpy\rinterface\r_utils.c /Fobuild\temp.win-amd64-3.6\.

Error: C stack usage is too close to the limit in Windows environment

你。 提交于 2019-12-11 00:35:30
问题 I'm doing geostatistical interpolations in R on a 5600 x 5700 matrix and, despite having available memory, I'm getting the error "C stack usage is too close to the limit." There are a few SO questions related to this issue including this one and this one. These sources and others I've seen online suggest changing the stack size often resolves this issue. Some suggested this change: R_CStackLimit = (uintptr_t)-1 in the file "Rinterface.h". However I am on Windows 7 (x64), using R 2.15.3 (x64)

splitting and concatenating dataframes in Python pandas for plotting with rpy2

可紊 提交于 2019-12-10 18:56:39
问题 I have a question about pandas dataframes in Python: I have a large dataframe df that I split into two subsets, df1 and df2 . df1 and df2 together do not make up all of df , they are just two mutually exclusive subsets of it. I want to plot this in ggplot with rpy2 and display the variables in the plot based on whether they come from df1 or df2 . ggplot2 requires a melted dataframe so I have to create a new dataframe that has a column saying whether each entry was from df1 or df2 , so that

How to get data from R to pandas

萝らか妹 提交于 2019-12-10 18:47:06
问题 In a jupiter notebook I created some 2-d-list in R like %%R first <- "first" second <- "second" names(first) <- "first_thing" names(second) <- "second_thing" x <- list() index <- length(x)+1 x[[index]] = first x[[index +1]] = second a %Rpull x does not return the nice representation but rather a ListVector . How can I convert it into something nicer e.g. a dict / pd.Dataframe? So far I had no luck following http://pandas.pydata.org/pandas-docs/stable/r_interface.html edit The list I want to

rpy2 (version 2.3.10) - importing data from R package into python

[亡魂溺海] 提交于 2019-12-10 17:59:50
问题 So I am trying to import some data from an R package into python in order to test some other python-rpy2 functions that I have written. In particular, I am using the SpatialEpi package in R and the pennLC dataset. So I was able to import the rpy2 package and connect to the package correctly. However, I am not sure how to access the data in the package. import rpy2.robjects as robjects from rpy2.robjects.packages import importr spep = importr("SpatialEpi") However, I can't seem to access the