R and Python in one Jupyter notebook

前端 未结 5 721
春和景丽
春和景丽 2020-12-02 04:59

Is it possible to run R and Python code in the same Jupyter notebook. What are all the alternatives available?

  1. Install r-essentials and create R notebooks in J
5条回答
  •  执念已碎
    2020-12-02 05:41

    SoS kernel is another option.

    Don't know how well it performs yet, just started using it.

    The SoS kernel allows you to run different languages within the same notebook, including Python and R.

    SoS Polyglot Notebook - Instructions for Installing Desired Languages

    Here is an example of a notebook with Python and R cells.


    *Update:

    In terms of sharing variables, one can use the magics %use and %with. "SoS automatically shares variables with names starting with sos among all subkernels"1.

    Ex.

    Starting cell in R:

    %use R
    sos_var=read.csv('G:\\Somefile.csv')
    dim(sos_var)
    

    Output:

    51  13
    

    Switching to python:

    %with Python3
    sos_var.shape
    

    Output:

    (51, 13)
    

提交回复
热议问题