Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
writeLines()在transformation-r tm包之后返回blank.txt_R_Tm - Fatal编程技术网

writeLines()在transformation-r tm包之后返回blank.txt

writeLines()在transformation-r tm包之后返回blank.txt,r,tm,R,Tm,我正在创建语料库,并使用tm包转换一堆.txt文件。这些.txt文件包含我从网页复制和粘贴的文本。运行语料库代码后,我运行了writeLines(as.character)函数来检查文件。但是,返回的三个.txt文件为空 然后,在我将大小写和标点符号转换如下后,更多的文件返回为空白 docs <- Corpus(DirSource(...)) docs <-tm_map(docs,content_transformer(tolower)) toSpace <- content_

我正在创建语料库,并使用
tm
包转换一堆
.txt
文件。这些
.txt
文件包含我从网页复制和粘贴的文本。运行语料库代码后,我运行了
writeLines(as.character)
函数来检查文件。但是,返回的三个
.txt
文件为空

然后,在我将大小写和标点符号转换如下后,更多的文件返回为空白

docs <- Corpus(DirSource(...))
docs <-tm_map(docs,content_transformer(tolower))
toSpace <- content_transformer(function(x, pattern) { return (gsub(pattern, " ", x))})
docs <- tm_map(docs, toSpace, ":")
docs <- tm_map(docs, toSpace, "–")
docs <- tm_map(docs, toSpace, "’")
docs <- tm_map(docs, toSpace, "'")
docs <- tm_map(docs, toSpace, ".")
docs <- tm_map(docs, toSpace, "“")
docs <- tm_map(docs, toSpace, "”")
writeLines(as.character(docs[[10]]))

docs
gsub
使用regex,因此
gsub(“.”,“”,x)
将用空格替换每个字符。您需要将其删除:
gsub(“\\.”,“,”,x)
谢谢您的回复。我把“.”的代码改成了“\\”,它成功了!