【发布时间】:2021-06-22 03:51:03
【问题描述】:
我有一个大的 csv 文件,我想将其导入 Rstudio。因为它太大(~29GB),我想一次只导入特定的行,而不是导入整个东西然后过滤。我一直在尝试在fread() 的cmd = 参数中使用grep,但是,我不断收到这样的消息
'grep' is not a recognized internal or external command, operable program, or batch file.
我已经安装了http://cygwin.com,甚至尝试手动将路径(C:\cygwin64\bin)添加到 Windows 环境,但仍然不断收到错误消息。
因此,我想我有两个问题:
- 使用 fread 将 CSV 导入 Rstudio 时如何让 grep 工作?
- 一旦 grep 工作,我将使用什么语法只导入包含特定字符串的行?
library(rgbif)
library(data.table)
#Download the csv (note: downloads a zip file ~7GB, unzipped ~29GB
occ_download_get("0299151-200613084148143") #add argument, path = ,if you want to direct the download
#I now only want to import the rows that contain "Acanthiza pusilla", for example.
fread() # it's here that I am unsure of the correct syntax
任何帮助将不胜感激。此外,如果您需要更多信息,请告诉我。 谢谢
【问题讨论】:
-
更改路径后是否重新启动了 R?在 R 中,
Sys.which("grep")是否返回正确的路径。请准确显示您的fread()代码的外观,以明确您尝试了什么。 -
谢谢@MrFlick。添加路径后,我确实忘记重新启动 R。从那以后,我想出了如何在 fread 中使用 grep。 @foreach 的回答也有帮助。我最终得到了以下工作
fread(cmd = paste("grep", "Acanthiza.pusilla", filename))