是否可以从现有r版本创建r conda环境? [英] Is it possible to create an r conda environment from an existing version of r?
问题描述
很久以前,我在计算机上安装了R 3.6,它具有我通常使用的所有软件包.我想使用此版本的R制作jupyter笔记本,但是我的R conda环境是r的不同版本,并且没有我的典型软件包.有没有办法从我的非conda版本的R创建新的R conda环境?和/或,还有什么方法可以将我首选的非conda版本的R作为Jupyter Notebooks的内核使用?
I had R 3.6 installed on my computer a long time ago and it has all of the packages that I typically use. I wanted to make a jupyter notebook using this version of R, however my R conda environment is a different version of r and has none of my typical packages. Is there a way to create a new R conda environment from my non-conda version of R? And/or, is there still a way I can use my preferred non-conda version of R as a kernel in Jupyter Notebooks?
推荐答案
否,不能将非Conda版本的R用作Conda环境的基础.
No, a non-Conda version of R cannot be used as a basis for a Conda environment.
但是,可以将任何R安装都用作Jupyter中的内核,无论在哪里安装都可以.这样做的关键是在R环境中安装IRkernel软件包.
However, it is possible to use any R installation as a kernel in Jupyter, no matter where either are installed. The key to doing so is to install IRkernel package in the R environment.
-
如果Jupyter安装在Conda env中,例如
my_jupyter_env
,请首先激活该env:
If the Jupyter is installed in a Conda env, e.g.,
my_jupyter_env
, first activate that env:
$ conda activate my_jupyter_env
(my_jupyter_env) $
否则,即 jupyter
位于 PATH
上,然后继续操作而不激活任何Conda环境.
Otherwise, i.e., jupyter
is on PATH
, then just continue without any Conda envs activated.
使用本地R启动R会话:
Start an R session using the native R:
(my_jypyter_env) $ path/to/native/R
安装 IRkernel
:
> install.packages("IRkernel")
请注意,如果此R位于Conda env中,请在R会话之外使用 conda install r-irkernel
.
Note that if this R is in a Conda env, instead use conda install r-irkernel
outside of the R session.
在R会话中,将R注册为内核.例如,如果我本机安装了R 3.6.0,则可以将其命名为:
From the R session, register R as a kernel. For example, if I had an R 3.6.0 natively installed I might call it:
> IRkernel::installspec(name="ir36_native", displayname="R 3.6.0 (native)")
但是参数是您想要的.
退出会话并启动Jupyter.
Quit the session and start Jupyter.
> q()
(my_jupyter_env) $ jupyter notebook
使用"新"按钮来创建一个新笔记本,然后从下拉菜单中选择R内核.
Use the "New" button to create a new notebook and select the R kernel from the dropdown.
这篇关于是否可以从现有r版本创建r conda环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!