linux r语言写的包怎么使用方法,R包安装使用指南

R包安装

R的版本要求:Windows和MacOS系统需要R 3.4,Linux系统需要R 3.2.3。

可以使用anaconda来管理R的版本。TopWORDS的R包目前可以通过以下步骤进行安装。

1. 安装anaconda

2. 安装R3.4

conda create -n R3.4 # 创建名为R3.4的环境

source activate R3.4 # 进入环境

conda install -c r r=3.4 # 安装R语言,版本为3.4

3. 安装TopWORDS包

R # 进入R语言环境

install.packages("Rcpp")

# Windows 系统

install.packages("http://www.stat.tsinghua.edu.cn/kdeng/wp-content/uploads/sites/2/2017/11/TopWORDS_1.1.zip", repos = NULL, type = "win.binary")

# MacOS 系统

install.packages("http://www.stat.tsinghua.edu.cn/kdeng/wp-content/uploads/sites/2/2017/09/TopWORDS_1.1_binary_mac.zip", repos = NULL, type = "mac.binary")

# Linux 系统

install.packages("http://www.stat.tsinghua.edu.cn/kdeng/wp-content/uploads/sites/2/2017/09/TopWORDS_1.1_binary_linux.tar_.gz", repos = NULL)

安装成功后输入 require("TopWORDS")  可显示载入信息。

使用方法

TopWORD的R包中包含topwords函数,命令格式为:

topwords(DataFile = "", ItemMode = "cen", MaxWordLen = 20L, MinWordFreq = 5L, WordSeparator = "|", MarkItemFilePath = "", WordDictFilePath = "")

其中,主要的参数DataFile为目标文本,MaxWordLen为判定作词组的字数上限,MinWordFreq为词组纳入词典需要出现的最小频数。

代码示例:

library(TopWORDS)

getwd() # 输出文件的位置路径

topwords("text_file.txt", MaxWordLen = 8, MinWordFreq = 5)

更多参数说明及代码示例请输入 ?topwords 查阅topwords函数的帮助文档。

成功运行后,topwords函数将输出5个文本文件作为结果:

TopWORDS_log.txt 是程序的日志文件,记录程序运行的详细细节;

TopWORDS_ItemSet.txt 列出了单字出现的次数;

TopWORDS_CompleteDict.txt 列出了程序初始化生成的完整词典;

TopWORDS_WordDict.txt 列出了程序通过优化和模型选择得到的最终词典;

TopWORDS_SegmentedText.txt 给出了最终的文本分词结果。

注意事项

该工具目前仅能处理UTF-8编码的文本。R包限制文本字符不超过50万个。

相关论文

Deng, K., Bol, P. K., Li, K. J., & Liu, J. S. (2016). On the unsupervised analysis of domain-specific Chinese texts. Proceedings of the National Academy of Sciences of the United States of America, 113(22), 6154–6159. http://doi.org/10.1073/pnas.1516510113

作者

Ke Deng (邓柯,副教授)

常见问题

1. 如果出现以下错误信息,请重新启动R。相关问题我们正在尽力解决。

Error in topwords() :

Error 'O0': fail to open file 'TopWORDS_log.txt'!

2. 升级R可以参考如下代码

# Windows 系统

install.packages("installr")

require(installr)

updateR()

# MacOS 系统

install.packages('devtools')

library(devtools)

install_github('andreacirilloac/updateR')

library(updateR)

updateR(admin_password = 'Admin user password') # change the quoted sentence into password

致谢

如果您在使用时遇到问题,或者有任何意见建议,欢迎发邮件至 stats@tsinghua.edu.cn。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值