Google colab中常用操作
1.执行命令行
1.1 执行python文件
google colab中不能像python代码中直接使用os.system('***')
,但可以通过以下方式实现:
%%shell
main.py -p ***
1.2 执行.sh文件
%%shell
bash ***.sh
或者直接使用:
!bash ***.sh
1.3 执行R程序
1.3.1 加载rpy2.ipython
%load_ext rpy2.ipython
然后就像在R studio中一样可以正常使用命令行了。
- 执行语句
%%R
outfile = "results/tem.txt" # A list of sequence IDs
a=10000
# Write sequence IDs to file
write.table(
a,
outfile, row.names=F, col.names=F, quote=F
)
- 执行R文件
%%R
source("***.R")
1.3.2 os.system()
这可是python中调用其他执行程序的常规操作!
os.system("**.R parm1 parm2)
这样就不需要东奔西走,费尽心机去搭建各种环境了。
2.Colab中的Rscript环境
可以通过如下两个网站,直接进入R环境,自由使用colab玩R:
参考文献
[1] Rmagic:Magic command interface for interactive work with R in ipython