[R] more rpy2 questions...mostly R

Collin Lynch collinl at cs.pitt.edu
Mon Nov 18 04:17:12 CET 2013


Erin, at first glance I would say that this is an R error.  When Rpy2
detects an error it will pass it through errors as library errors like
this.  At first glance it appears that your r code is not loading the
requisite packages as it cannot find them.  That I suspect is what is
causing your coordinates error.

I would first run R and confirm that you can load the requisite libraries
in it before depending upon them in rpy2.  In general I find that rpy2 is
a bad interface for debugging R code and you need to run it in R first to
get the problems out.

	Best,
	Collin.

On Sun, 17 Nov 2013, Erin Hodgess wrote:

> Hello again!
>
> I'm using python, rpy2, and R for a project.  It's actually pretty
> interesting.  Anyhow, I pass in an R file to the python program.  However,
> I am getting the following errors, which seem more like R errors(?):
>
> Loading required package: gstat
> Loading required package: automap
> Error in coordinates(x.df) <- ~x + y :
>   could not find function "coordinates<-"
> In addition: Warning messages:
> 1: In library(package, lib.loc = lib.loc, character.only = TRUE,
> logical.return = TRUE,  :
>   there is no package called ‘gstat’
> 2: In library(package, lib.loc = lib.loc, character.only = TRUE,
> logical.return = TRUE,  :
>   there is no package called ‘automap’
> Traceback (most recent call last):
>   File "reg4.py", line 38, in <module>
>     spat1.spat1(file1=file1,file2=file2)
>   File "/usr/local/lib/python2.7/site-packages/rpy2/robjects/functions.py",
> line 86, in __call__
>     return super(SignatureTranslatedFunction, self).__call__(*args,
> **kwargs)
>   File "/usr/local/lib/python2.7/site-packages/rpy2/robjects/functions.py",
> line 35, in __call__
>     res = super(Function, self).__call__(*new_args, **new_kwargs)
> rpy2.rinterface.RRuntimeError: Error in coordinates(x.df) <- ~x + y :
>   could not find function "coordinates<-"
>
> I've checked and gstat and automap are both there.  Here is the actual R
> code:
> spat1 <- function(file1,file2) {
>     require(gstat)
>     require(automap)
>     x.df <- read.table(file=file1,header=TRUE)
>     coordinates(x.df) <- ~x+y
>     zz <- scan(file=file2,what="character")
>     proj4string(x.df) <- zz
>     png(file="map1.png")
>     u <- autoKrige(x.df at data[,1]~1,x.df)
>     plot(u)
>     return(u)
> }
>
>
> I know that there are a few people who have used both rpy2, python and R,
> so I thought I'd launch this out.
>
> Thanks in advance for any help.
>
> Sincerely,
> Erin
>
>
> --
> Erin Hodgess
> Associate Professor
> Department of Computer and Mathematical Sciences
> University of Houston - Downtown
> mailto: erinm.hodgess at gmail.com
>
> 	[[alternative HTML version deleted]]
>
>



More information about the R-help mailing list