%% Cell Magic标签在Jupyter笔记本电脑中不起作用? [英] %% Cell magic tag not working in Jupyter notebook?
问题描述
我是Jupyter笔记本电脑的新手,我正在尝试使用rpy2使用Python和R进行设置.我有线
I'm new to Jupyter notebook and I'm trying to set one up with Python and R, using rpy2. I have the line
%%R -i df
出现错误SyntaxError:语法无效
which gives me the error SyntaxError: invalid syntax
但是,当我只使用一个百分比时,例如
However when I use just one %, such as
%R require(ggplot2)
这很好用.如何解决此问题?我正在使用Python 2.7.
this works fine. How can I fix this issue? I am using Python 2.7.
推荐答案
%
前缀用于线魔术,而%%
前缀用于单元魔术.
%
prefix is for a line magic, whereas %%
prefix is for a cell magic.
%%R # <-- must be the only instruction on this line
{body of cell in R code}
而:
%R {one line of R code}
我没有安装R,但是我认为您可能想在R上调用bash命令;在这种情况下,请使用!
调用命令:
I don't have R installed, but I think you may have wanted to call a bash command on R; in that case, use !
to call the command:
!R -i df
例如,如果我键入!python -i
,我会得到有关当前python环境的信息:
for instance, if I type !python -i
, I get info about my current python environment:
Python 3.6.2 |Anaconda custom (x86_64)| (default, Jul 20 2017, 13:14:59)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
这篇关于%% Cell Magic标签在Jupyter笔记本电脑中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!