我希望在我的環境中讀入一個大的 CSV(~ 8Gb),但我遇到了問題。
我的資料是一個公開可用的資料集:
# CREATE A TEMP FILE TO STORE THE DOWNLOADED DATA
temp <- tempfile()
# DOWNLOAD THE FILE FROM THE CMS
download.file("https://download.cms.gov/nppes/NPPES_Data_Dissemination_February_2022.zip",
destfile = temp)
這是我遇到困難的地方,我不熟悉 linux 作業目錄以及創建臨時檔案夾的位置。
當我使用list.dir()或list.files()沒有看到對此臨時檔案的任何參考時。
我在一個 R 專案中作業,我的作業主管如下:
getwd()
[1] "/home/myName/myProjectName"
我能夠讀取檔案的第一部分,但我的系統在大約 4Gb 后崩潰。
# UNZIP THE NPI FILE
npi <- unz(temp, "npidata_pfile_20050523-20220213.csv")
然后我遇到了
任何關于如何解壓縮這個檔案并將其讀入記憶體的指標將不勝感激。
uj5u.com熱心網友回復:
可能是檔案權限問題。要繞過它,請在您已經在其中或知道您可以訪問的目錄中作業。
# DOWNLOAD THE FILE
# to a directory you can access, and name the file. No need to overcomplicate this.
download.file("https://download.cms.gov/nppes/NPPES_Data_Dissemination_February_2022.zip",
destfile = "/home/myName/myProjectname/npi.csv")
# use the decompress function if you need to, though unzip might work
x <- decompress_file(directory = "/home/myName/myProjectname/",
file = "npi.zip")
# remove .zip file if you need the space back
file.remove("/home/myName/myProjectname/npi.zip")
uj5u.com熱心網友回復:
temp是檔案的路徑,而不僅僅是目錄。默認情況下,tempfile不添加檔案擴展名。它可以通過使用來完成tempfile(fileext = ".zip")
因此,decompress_file不能將作業目錄設定為檔案。嘗試這個:
x <- decompress_file(directory = dirname(temp), file = basename(temp))
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/441865.html
