R and Python Integration

Run 'Python' code, make function calls, assign and retrieve variables, etc. from R. A fork from 'rPython' which uses 'jsonlite', 'Rcpp' and has several fixes and improvements.

Travis-CI Build Status AppVeyor Build Status codecov


Modern overhaul of rPython, read more on the motivation and benefits of using it in this blog post.

Many thanks to Bob Rudis for basically teaching me how to write a modern R package and getting this off the ground.

In order to compile SnakeCharmR, you'll need to have Python >= 2.7 installed. Make sure you also have the development libraries and include files, the operating system package names will vary with your specific Linux distribution.

By default SnakeCharmR will look for python-config and python commands in the PATH. The former will be used to determine the location of the libraries and headers necessary to compile SnakeCharmR.

In systems where several Python versions coexist, you can force a different version to be used by setting an environment variable SNAKECHARMR_PYTHON_VERSION to either the major version or major and minor versions.

For example, if you set SNAKECHARMR_PYTHON_VERSION=3.2 then Python 3.2 will be used. In this example, you will need to ensure:

  • that python3.2 and python3.2-config exist and are in the PATH;

  • that a libpython3.2.so exists at the locations indicated by python3.2-config --ldflags.


In order to compile this on Windows, make sure you meet the following requirements:

  • Install the latest version of Rtools;

  • Ensure the python command from the desired Python version is the first one in your PATH.

If you want to use the (very outdated) Python bundled with Rtools on a 64-bit system, for example, you would need to add c:\Rtools\mingw_64\opt\bin to your PATH and possibly set PYTHONHOME to c:\Rtools\mingw_64\opt.

It is recommended, however, that you install and use the official Python distribution for Windows.

Many thanks to mattfidler for the help in getting this to work properly on Windows.


SnakeCharmR 1.0.7

Avoid tripping maximum R string size when reading large data objects from Python. The JSON string string read from Python is stored into a raw vector, which is then read with jsonlite's push parser through a rawConnection.

Should now compile on Windows using the Rtools Python libraries or the standard Python package. Many thanks to Matthew Fidler (https://github.com/mattfidler), his help was invaluable in helping implement and test this.

Added Appveyor tests for the Windows build.

SnakeCharmR 1.0.6

Fixed compilation on Python 3, fixing https://github.com/asieira/SnakeCharmR/issues/33. Thanks to https://github.com/lfdmotta for reporting this.

Updated Travis tests to cover Python 2 and 3, and also current and devel versions of R.

Startup message will now include contents of Python sys.version information.

SnakeCharmR 1.0.5

Cleaned up configure.ac and src/Makevars.in to remove unnecessary steps inherited from RPython code.

Fixed issue with logo image in README file in CRAN page.

Updated versions of package dependencies.

SnakeCharmR 1.0.4

Fixed https://github.com/asieira/SnakeCharmR/issues/24. Thanks to David Severski (@dseverski) for reporting this.

SnakeCharmR 1.0.3

Took measures to ensure SnakeCharmR will work properly on systems where the native encoding is not UTF-8:

  • Use Python API to check if variable is str/bytes or unicode and handling things correctly. In particular, when we read Python unicode values we flag the resulting R string as UTF-8 since that’s what we Python C API we are using will return;

  • Ensure that Python code being executed is converted to UTF-8 and that the Python interpreter is made aware of that according to PEP 263.

SnakeCharmR 1.0.2

Fixed linking and building errors on some platforms (such as Amazon Linux) by updating the autoconf file to use the correct C++ compiler preferred by R.

SnakeCharmR 1.0.1

Fixed handling of NULL values in arguments, including a workaround for jeroenooms/jsonlite#130 which was causing inconsistencies.

SnakeCharmR 1.0.0

Initial release.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("SnakeCharmR") by Alexandre Sieira, 6 months ago


Report a bug at https://github.com/asieira/SnakeCharmR/issues

Browse source code at https://github.com/cran/SnakeCharmR

Authors: Alexandre Sieira , forked off of rPython by Carlos J. Gil Bellosta

Documentation:   PDF Manual  

Task views: Numerical Mathematics

GPL-2 license

Imports jsonlite, stringr, Rcpp, utils

Suggests testthat

Linking to Rcpp

System requirements: Python (>= 2.7) and Python headers and libraries (See the README.md file)

Suggested by RxODE.

See at CRAN