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:
function name R type python type 1 pydict list dictionary 2 pylong integer list of long 3 pyfloat numeric list of float 4 pybool logical list of bool 5 pystr character list of strThe 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.