2016-11-29 149 views
0

我想複製下面的代碼來模擬一些圖表,我在下載(我猜)時出錯並讀取.csv文件。問題是我不知道如何或在哪裏創建「輸入」目錄,如何在命令行中放置路徑以及是否下載數據。任何人都可以幫忙?謝謝你的時間!讀取CSV文件並創建路徑

library(idbr) 
library(countrycode) 
library(ggplot2) 
library(animation) 
library(dplyr) 


countries <- c("France", "Switzerland", "Japan", "China", "United States", "Brazil", "Russia", "Morocco") 
country.iso2 <- countrycode(countries, "country.name", "fips104") 

translation.file <- "input/Population structures past and forecast - Sheet1.csv" 

downloadData <- F 

years <- 1990:2050 
apikey <- "901083ee90dbd111d13f5e270ca00b4abf654be6" 
data.file <- paste0("input/", paste(range(years), collapse = "_"), "_", 
paste(country.iso2, collapse = "_"), ".csv") 

### load translations 
txt <- read.csv(translation.file, row.names = 1, stringsAsFactors = F) 

Error in file(file, "rt") : no se puede abrir la conexión 
Además: Warning message: 
In file(file, "rt") : 
no fue posible abrir el archivo 'input/Population structures past and forecast - Sheet1.csv': No such file or directory 
+0

請正確標記您的問題。看來你正在使用'R',所以補充一點。 –

+0

@ Ansjovis86我的印象是OP沒有在當前工作目錄中創建'input'目錄,這阻止了R創建csv文件。 –

回答

0

谷歌搜索r create dir導致我this SO question這表明您可以使用dir.create創建目錄。請注意,您需要在創建目錄的位置擁有寫入權限,例如您的主驅動器。您可以使用tempdir()來獲取臨時目錄,您可以在其中存儲內容,這適用於Linux,Windows和Mac。