Embed python in R
Ubuntu with python 2.7
Please install the following ubuntu packages:
library(Rython) py("python script")
To pass object from R to python, use the following functions:
library(xtable) type.mapping <- matrix(dimnames=list(NULL, c("function name", "R type", "python type")), byrow=TRUE, ncol=3, c( "pydict", "list", "dictionary", "pylong", "integer", "list of long", "pyfloat", "numeric", "list of float", "pybool", "logical", "list of bool", "pystr", "character", "list of str" )) print(xtable(type.mapping), type="html")
The following script query the Cassandra with python-cql 1.4 and pass the value back to R
library(Rython) py("import cql") py("con = cql.connect(host, port, key_space, cql_version='3.0.0')") py("cursor = con.cursor()") py("cursor.execute('select * from column_family limit 1')") py("result = cursor.fetchall()") py("print result") py("result1 = result[0]") result1 <- pyobj(obj_name="result1", module_name="") pywrap(result1)
Put your python script under inst/python
and install it.
#'@export .onLoad <- function(libname, pkgname) { import_pkg_module(pkgname, "foo.py") }
R/conversion.R
)Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.