我刚开始使用RStudio和Python(目前一切正常),我想知道是否有一种首选的方法来运行脚本,例如我的小Test.py
包含以下内容:
import inspect
import os
a = 5
print(a)
print(inspect.currentframe())
os.chdir("C:/.../") # a path, whatever you like
cwd = os.getcwd()
# print the current directory
print("Current working directory is:", cwd)
这里有一个关于R的答案,点击此处,但是它没有考虑Python。我尝试了以下操作:
- 在R-console中使用源代码(Ctrl + Shift + S) => 使用R-console
- 使用
reticulate::repl_python()
在R-console中启动Python console => 从R-切换到Python-console
- 在Python-console中使用源代码(Ctrl + Shift + S) => 从Python-切换到R-console
从结果来看,reticulate::repl_python()
会先强制执行quit
命令。
- 使用“run”(Ctrl + Enter)运行一行或多行代码 => 启动Python-console,并保持打开状态
这个关于reticulate的参考文档和它的描述没有帮助: reticulate包提供了一整套工具,用于实现Python和R之间的互操作性...... Reticulate将一个Python会话嵌入到您的R会话中,实现了无缝的高性能互操作性。
时,它仍然会抛出一个错误。
Error in py_run_file_impl(file, local, convert) : IndexError: list index out of range`) - Christoph