搜索
查看: 1990|回复: 0

[R] 把简单的字符串写到文本里面-R

[复制链接]

634

主题

1182

帖子

4030

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
4030
发表于 2017-3-31 09:06:19 | 显示全部楼层 |阅读模式
我是谷歌看到的,在perl或者python等语言很简单,就是print咯
但是R里面我们习惯了格式化的数据,一般是table输入输出的。
如果只有一个字符串,但就是想输入到文本,比如一个json
[AppleScript] 纯文本查看 复制代码
[
{"showscoreidx": 0, "mode": "barplot", "url": "http://dc2.cistrome.org/data5/browser/44026_sort_peaks.narrowPeak.bed.gz", "scorenamelst": ["signal value", "P value (-log10)", "Q value (-log10)"], "strokecolor": "#ff6600", "type": "hammock", "boxcolor": "#210085", "name": "44026_PC-3_AGO1"}, {"url": "http://dc2.cistrome.org/data5/browser/44026_treat.bw", "type": "bigwig", "mode": "show", "name": "44026_PC-3_AGO1", "height": 50}, 
{"showscoreidx": 0, "mode": "barplot", "url": "http://dc2.cistrome.org/data5/browser/48594_sort_peaks.narrowPeak.bed.gz", "scorenamelst": ["signal value", "P value (-log10)", "Q value (-log10)"], "strokecolor": "#ff6600", "type": "hammock", "boxcolor": "#210085", "name": "48594_MCF-7_AGO1"}, {"url": "http://dc2.cistrome.org/data5/browser/48594_treat.bw", "type": "bigwig", "mode": "show", "name": "48594_MCF-7_AGO1", "height": 50}, 
{"showscoreidx": 0, "mode": "barplot", "url": "http://dc2.cistrome.org/data5/browser/48609_sort_peaks.narrowPeak.bed.gz", "scorenamelst": ["signal value", "P value (-log10)", "Q value (-log10)"], "strokecolor": "#ff6600", "type": "hammock", "boxcolor": "#210085", "name": "48609_None_AGO1"}, {"url": "http://dc2.cistrome.org/data5/browser/48609_treat.bw", "type": "bigwig", "mode": "show", "name": "48609_None_AGO1", "height": 50}, 
{"showscoreidx": 0, "mode": "barplot", "url": "http://dc2.cistrome.org/data5/browser/48610_sort_peaks.narrowPeak.bed.gz", "scorenamelst": ["signal value", "P value (-log10)", "Q value (-log10)"], "strokecolor": "#ff6600", "type": "hammock", "boxcolor": "#210085", "name": "48610_MCF-7_AGO1"}, {"url": "http://dc2.cistrome.org/data5/browser/48610_treat.bw", "type": "bigwig", "mode": "show", "name": "48610_MCF-7_AGO1", "height": 50}
]

咋办呢,就需要用sink+cat了,类似于打开文件句柄,再写入字符。
[AppleScript] 纯文本查看 复制代码
sink("outfile.txt")
cat("hello")
cat("\n")
cat("world")
sink()


还有一个好玩的东西是file.show("outfile.txt") 可以调用系统默认软件把txt文本打开,一般人的默认软件是notepad咯




上一篇:用bioDBnet在线工具来转换ID
下一篇:ubuntu等linux系统安装xml和RCurl包缺少关键文件
你这个问题很复杂,需要打赏,请点击 http://www.bio-info-trainee.com/donate 进行打赏,谢谢
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|生信技能树 ( 粤ICP备15016384号  

GMT+8, 2019-10-22 23:00 , Processed in 0.036625 second(s), 26 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.