R中的文本文件没有加载R中的所有文本

问题描述:

当我将一个文件上传到R文本文件被截断,我无法获得准确的计数。是否有另一个命令我应该使用,以便我读取整个文本文件。R中的文本文件没有加载R中的所有文本

library(stringr) 
> readr::read_file("Apple_Wikipedia.txt") 
[1] "Apple Inc. is an American multinational technology company headquartered in Cupertino, California that designs, develops, and sells consumer electronics, computer software, and online services. The company's hardware products include the iPhone smartphone, the iPad tablet computer, the Mac personal computer, the iPod portable media player, the Apple Watch smartwatch, the Apple TV digital media player, and the HomePod smart speaker. Apple's consumer software includes the macOS and iOS operating systems, the iTunes media player, the Safari web browser, and the iLife and iWork creativity and productivity suites. Its online services include the iTunes Store, the iOS App Store and Mac App Store, Apple Music, and iCloud.\r\nApple was founded by Steve Jobs, Steve Wozniak, and Ronald Wayne in April 1976 to develop and sell personal computers. It was incorporated as Apple Computer, Inc. in January 1977, and sales of its computers saw significant momentum and revenue growth for the company.... <truncated> 
> x <- c("Apple","ios", "iphone") 
> str_count(x) 
[1] 5 3 6 

首先需要指定文本在河的实际对象目前你只是在文本阅读,而不会有任何保存它,然后在不恰当的方式调用str_count,所以它只是返回字符串中的字符数'Apple'(5),'ios'(3)和'iphone'(6)。 R控制台中的文本显示在某些时候仍然会被截断,但数据将被完全保存。以下应该工作。

library(stringr)  
    apple_wiki <- readr::read_file("Apple_Wikipedia.txt") 
    x <- c("Apple","iOS", "iPhone") 
    str_count(apple_wiki, x) 

也请注意,str_count是大小写敏感的,所以要小心与维基条目匹配您的字词或使用正则表达式或文本转换来解决它。