简体   繁体   English

在 Jupyter Notebook 上的 macbook 上安装 rpy2

[英]rpy2 installation on macbook on Jupyter Notebook

Trying to install rpy2 modules on terminal and there is no action.尝试在终端上安装rpy2模块,但没有任何操作。

Trying to directly install rpy2 on cell尝试直接在单元格上安装rpy2

!pip install rpy2
%load_ext rpy2.ipython
%%R -i data 
data <- list('0.47', '-0.36', '-0.5', '0.2', '0.35', '1.82', 
             '-0.78', '-0.91', '0.36', '-1.74', '0.24', '0.76', 
             '0.57', '2.32', '1.55', '-1.31', '-0.09', '-0.02', 
             '-0.07', '-0.19', '-0.25', 
             '-1.09', '0.64', '1.22', '-0.56', '1.76', '0.13', 
             '1.33', '-0.74', '-1.15', '1.63', '1.04', '-0.26', 
             '0.02', '-1.2', '0.37', '0.43', '0.04', '1.34', 
             '0.57', '0.76', '-1.25', '-0.05', '0.12', '0.8', 
             '-0.99', '-0.11', '-0.54', '-0.08', '-0.04', '-0.76', 
             '-0.8', '0.35', '1.54', '-0.99', '-0.35', '-0.28', '0.45', 
             '-0.04', '-0.06', '0.02', '0.58', '-0.32', '-0.1', '0.28', 
             '0.3', '-0.36', '0.81', '0.79', '0.21', '1.81', '0.19', '0.84', 
             '0.2', '-0.06', '-0.11', '-1.4', '-2.08', '0.88', '-0.14',
             '-0.96', '1.3', '0.06', '-0.37', '1.49', '-0.91', 
             '1.14', '-1.05', '1.49', '-0.79', '2.02', '0.38', '2.4', '1.25', 
             '0.5', '1.11', '-0.54', '-0.1', '0.63', '1.01')
num <- as.numeric(unlist(data))
shapiro.test(num)
shapiro.test

The results show结果显示

 File "<ipython-input-3-0be657748cce>", line 20
    num <- as.numeric(unlist(data))
           ^
SyntaxError: invalid syntax

It still doesn't work还是不行

I just wanna the R code to be attached on my Jupyter notebook.我只想将 R 代码附加到我的 Jupyter 笔记本上。

data <- list('0.47', '-0.36', '-0.5', '0.2', '0.35', '1.82', 
             '-0.78', '-0.91', '0.36', '-1.74', '0.24', '0.76', 
             '0.57', '2.32', '1.55', '-1.31', '-0.09', '-0.02', 
             '-0.07', '-0.19', '-0.25', 
             '-1.09', '0.64', '1.22', '-0.56', '1.76', '0.13', 
             '1.33', '-0.74', '-1.15', '1.63', '1.04', '-0.26', 
             '0.02', '-1.2', '0.37', '0.43', '0.04', '1.34', 
             '0.57', '0.76', '-1.25', '-0.05', '0.12', '0.8', 
             '-0.99', '-0.11', '-0.54', '-0.08', '-0.04', '-0.76', 
             '-0.8', '0.35', '1.54', '-0.99', '-0.35', '-0.28', '0.45', 
             '-0.04', '-0.06', '0.02', '0.58', '-0.32', '-0.1', '0.28', 
             '0.3', '-0.36', '0.81', '0.79', '0.21', '1.81', '0.19', '0.84', 
             '0.2', '-0.06', '-0.11', '-1.4', '-2.08', '0.88', '-0.14',
             '-0.96', '1.3', '0.06', '-0.37', '1.49', '-0.91', 
             '1.14', '-1.05', '1.49', '-0.79', '2.02', '0.38', '2.4', '1.25', 
             '0.5', '1.11', '-0.54', '-0.1', '0.63', '1.01')
num <- as.numeric(unlist(data))
shapiro.test(num)
shapiro.test

Your example is showing just R code without any python functions used.您的示例仅显示 R 代码,没有使用任何 python 函数。

Option 1 (easy, without jupyter and python)选项 1(简单,没有 jupyter 和 python)

If you really do not need Jupyter and python, you can just create documents with R code cells and text in between using RMarkdon inside RStudio.如果您真的不需要 Jupyter 和 python,您可以使用 RStudio 中的 RMarkdon 创建包含 R 代码单元和文本的文档。

Option 2 (hard, with jupyter and python)选项 2(困难,使用 jupyter 和 python)

  1. install R and python安装 R 和 python
  2. install Jupyter安装 Jupyter
  3. install rpy2 using ! pip install rpy2使用! pip install rpy2安装 rpy2 ! pip install rpy2 inside a jupyter cell ! pip install rpy2
  4. Run R code within the notebook:在笔记本中运行 R 代码:
import rpy2
%load_ext rpy2.ipython
%%R -o data 
data <- list(1,2,3)

Option 3 (medium, with jupyter using just R without python)选项 3(中等,jupyter 只使用 R,没有 python)

  1. install jupyter安装 jupyter
  2. install IRkernel安装IRkernel
  3. start juypter and choose the R kernel启动 juypter 并选择 R kernel
  4. write just R code in your jupyter cells:在你的 jupyter 单元格中只写 R 代码:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM