r - 将 r 包导入 jupyter 笔记本(使用 rpy2)的最佳方法是什么?
问题描述
我正在尝试使用 rpy2 将 r 包(标题为“afex”)导入到 jupyter notebook 中,以便于使用 python。但是,我收到“选择:”语句后跟空白行。我尝试在空白行中输入各种镜像链接,但是没有任何帮助。我很想听听是否有人可能遇到过这种情况并且可以提供帮助。
请参阅下面的代码:
#Importing key libraries.
import numpy as np
import pandas as pd
import seaborn as sns
import scipy.stats as stats
import matplotlib.lines as mlines
from matplotlib import pyplot as plt
from statsmodels.formula.api import ols
# Download rpy2 package
# Note: The r-modules require Rpy2 to be installed, which should first be done using
# "conda install -c conda-forge rpy2"
# using Jupyter lab within the conda navigator (terminal within there).
%load_ext rpy2.ipython
%load_ext rmagic
# Import the necessary objects from rpy2 and acrivate conversion for dataframe columns
from rpy2.robjects import *
pandas2ri.activate()
# Import the r library for anovas
#import afex
%R install.packages("afex")
这是问题(我在上述命令之后得到的输出): 选择:
还附上了问题截图的链接。问题截图
解决方案
默认情况下,R 会以交互方式要求用户选择一个应该从哪里下载包的镜像,并且由于某种原因,镜像列表不会显示在您的系统上(使用 Windows ? rpy2 不支持)。
请参阅文档以选择镜像并从 Python 安装:
https://rpy2.github.io/doc/v2.9.x/html/robjects_rpackages.html#installing-removing-r-packages
推荐阅读
- cuda - 无法在 Cuda Fortran 中调用设备函数
- java - eclips中的可流动项目构建问题
- python - Slack View_submission 未发布到当前窗口
- mongodb - Mongodb:按引用字段分组和求和
- python - 我正在尝试制作一个递归函数,不断要求用户决定他们想要如何处理 wav 文件
- node.js - Multer 错误无法上传大小超过 50kb 的文件
- javascript - 访问同一数组中对象中的重复项?
- pandas - 重组奇数行熊猫df
- firebase - Firebase 如何在内部处理 Flutter 依赖项
- graphql - 为什么中继现代分页似乎要返回所有项目?