首页 > 解决方案 > 将 R 指定为 nbformat 中的语言

问题描述

使用此处的帮助,我正在编写一个 python 代码来生成一个 Jupyter 笔记本。我的代码如下:

...
code1 = """\
a=[1,2,3]
for x in a:
    print(x)"""
cell1=nbf.v4.new_code_cell(code1)
code2="""\
myString <- 'Hello, World!'
print(myString)"""                  #note that it is in R
cell2=nbf.v4.new_code_cell(code2)
...

!jupyter nbconvert --execute --inplace test.ipynb用来执行我的代码,这样我就可以看到输出而无需运行最终的笔记本。

现在问题是我想cell1使用python运行,这是默认的(我猜)并cell2使用R。有没有办法实现这一点?谢谢...

标签: pythonrjupyter-notebook

解决方案


推荐阅读