Question

how to configure Sweave it's work and recognize for Rpy2?

I use this

 import rpy2.robjects as robjects

  R["library"]("utils")
  R["library"]("tools")
  R['sweave("/var/www/tmp/pywps/central.Rnw")']
  R['texi2dvi("/var/www/tmp/pywps/central.tex", pdf=TRUE)']

but I get these errors

[File "/usr/lib/python2.6/dist-packages/rpy2/robjects/__init__.py", line 241, in   __getitem__
    res = rinterface.globalenv.get(item)
    LookupError: 'Sweave("/var/www/tmp/pywps/central.Rnw")' not found
     Traceback (most recent call last):]

thanks for your answers and help

Was it helpful?

Solution

Use square brackets to get an R object, then call it from Python. Or use () brackets to pass a line to R:

R["Sweave"]("/var/www/tmp/pywps/central.Rnw")
R('Sweave("/var/www/tmp/pywps/central.Rnw")')

Sweave needs a capital S (in my tests).

OTHER TIPS

Uh, does this work? You're not doing all the R[] invocations the same way.

import rpy2.robjects as robjects

R["library"]("utils")
R["library"]("tools")
R["sweave"]("/var/www/tmp/pywps/central.Rnw")
R["texi2dvi"]("/var/www/tmp/pywps/central.tex", "pdf=TRUE")

(I've never used Rpy2 so this is totally guessing.)

Using the R package importer would let you use autocompletion in your IDE or interactive shell and make the code more Python-like.

from rpy2.robjects.packages import importr
utils = importr('utils')
utils.Sweave("/var/www/tmp/pywps/central.Rnw")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top